首页 > 编程语言 > 详细

Swift - use Array

时间:2016-01-14 12:09:22      阅读:235      评论:0      收藏:0      [点我收藏+]
//数组声明
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)

  

Swift - use Array

原文:http://www.cnblogs.com/qzp2014/p/5129679.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!