Swift - use Array

//数组声明
var arr0 = Array<Int>()
var arr1 = Array<String>(count: 3, repeatedValue: "")




var strs = ["Hello"]
print(strs.count) //个数
strs.append("Hi") //添加
print(strs.isEmpty) //判空

strs.appendContentsOf(["How", "Are", "Your"]) //添加数组
strs.insert("Bob", atIndex: 0) //插入
strs.removeLast()
print(strs)

strs.removeFirst(2) //移除前几个
print(strs)

strs.removeRange(strs.endIndex.advancedBy(-2) ..< strs.endIndex) //移除最后2个
print(strs)
strs.removeAll(keepCapacity: true) //移除所有但保留存储空间

strs += ["a","b"] //数组合并
strs.description
strs.debugDescription

strs[0] = "WWW" //替换




strs.reserveCapacity(2)
print(strs)

  

posted @ 2016-01-14 11:43  云影风雨  阅读(149)  评论(0编辑  收藏  举报