swift数组与字典类型操作使用-成都快上网建站

swift数组与字典类型操作使用

var studentList : [String] = ["张三","李四","王五"];

在洛宁等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站制作、成都做网站 网站设计制作按需网站设计,公司网站建设,企业网站建设,高端网站设计,营销型网站,外贸营销网站建设,洛宁网站建设费用合理。

//数组插入

studentList.insert("刘备",atIndex: 0)

//数组追加,每次调用只能追加一个元素

studentList.append("赵云");

//数组追加多元素

studentList += ["关羽","张飞"];

//数组遍历

for student in studentList {

    print(student);

}

打印结果:

刘备

张三

李四

王五

赵云

关羽

张飞

//字典类型如果拿java中的类型举例的话,与Map相似

var studentDictionary : Dictionary = [102 : "张三",105 : "李四",109 : "王五"]

print("字典遍历keys");

for studentIDinstudentDictionary.keys{

    print("学生ID:\(studentID)");

}

print("字典遍历values");

for studentNameinstudentDictionary.values{

    print("学生姓名:\(studentName)")

}

print("字典遍历键值对形式");

for (studentID, studentName) in studentDictionary{

    print("学生ID:\(studentID)学生姓名:\(studentName)")

}

//String类型的遍历,目前 xcode7 后不支持这种方式遍历了,如果使用xcode6.2则可以编译通过

var str : String = "10.9989";

for number in str {

}


当前名称:swift数组与字典类型操作使用
转载来源:http://kswjz.com/article/ghdodh.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流