学无止境啊,赶紧总结,最基本的知识===数组操作
//数组
var shopList = ["apple","pear"]
//获取下标元素
myLabel.text = shopList[0]
//数组增加元素
shopList += ["peach","waterPalon"]
println("1-1 the array is \(shopList) array count is \(shopList.count)")
//数组末尾添加一个元素
shopList.append("banana")
println("1-2 the array is \(shopList)")
//根据索引改变数组元素
shopList[1] = "yellow"
println("1-3 the array is \(shopList)")
//替换指定范围的元素
shopList[2...3] = ["red","blue","green","blue"]
println("1-4 the array is \(shopList)")
//插入到指定位置
shopList.insert("meat", atIndex: 3)
println("1-5 the array is \(shopList)")
//移除
shopList.removeLast()
println("1-6 the array is \(shopList)")
//移除某个下标的元素
shopList.removeAtIndex(0)
println("1-7 the array is \(shopList)")
//打印对应元素
for (index, value) in enumerate(shopList) {
println("Item \(index + 1): \(value)")
}
//==== 此行遍历的方法是xcode6中的方法,在xcode7中,使用
//打印对应元素
for (index, value) in shopList.enumerate() {
print("Item \(index + 1): \(value)")
}
2016-05-04 修改
另:println 用print 替代
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。