老猫swift学习笔记(三):数组
var arr:String[] = ["Allen","Jerry","Haley","Colin","Jay"] println("size : \(arr.count)") //5 //往数组末尾添加数据Linda arr += "Linda" //往数组末尾添加数据Angel arr.append("Angel") //往数组末尾添加数组 arr += ["Alan","Adm"] for item in arr { print("\(item) \t") } //print "Allen Jerry Haley Colin Jay Linda Angel Alan Adm" println() arr.removeAtIndex(2) //把Haley给删掉 var temp = arr.removeLast()//删除的元素 Adm println(temp) //Adm println(arr.isEmpty)//false for item in arr { print("\(item) \t") } //print "Allen Jerry Colin Jay Linda Angel Alan" println() //修改数据 arr[2] = "Doctor" for item in arr { print("\(item) \t") } //print "Allen Jerry Doctor Jay Linda Angel Alan " println() //修改多个 arr[2...3] = ["Update1","Update2"] for item in arr { print("\(item) \t") } //print "Allen Jerry Update1 Update2 Linda Angel Alan " println() //修改多个,如果后面提供的元素不足,无法赋值的元素将被删除 arr[2...5] = ["AA","BB"] //2...5 需要4个元素,但这里只提供了两个,所以第四、第五哥元素将被删除 for item in arr { print("\(item) \t") } //print "Allen Jerry AA BB Alan" println() //好吧关于数组就到这里为止,剩下的大家自己去尝试下
上一篇:swift for-in循环中"..."与".."的区别
转载请标注:swift开发者www.swift-open.com
相关推荐
renyingcai0 2020-03-08
我为人人 2015-01-24
iOS海马 2019-06-21
JackZeng 2019-06-21
JackZeng 2019-06-21
关东升 2019-06-20
ziyikongfu 2019-06-20
我为人人 2016-04-19
sunJingLove 2015-09-25
magiccastle 2015-01-24
swifter0 2014-06-24
PoppinCategory 2014-06-20
Beixiqi 2014-06-11
WorldofiOs 2014-06-11
liukaili 2014-06-09
magiccastle 2014-06-09
sunJingLove 2014-06-07
binglechen 2014-06-06
WorldofiOs 2014-06-06