(1)初始化
(2)新增、修改、删除
(3)清空
(4)遍历
- var array1 = ["x","y","z"]
- var array2:[String] = ["x","y","z"]
- var array3:Array<String> = ["x","y","z"]
-
- array1[0]
- array1[1]
-
- var array4 = []
- var array5 = [Int]()
- var array6 = Array<String>()
-
- array6.append("x")
- array6.append("y")
- array6.append("z")
- array6 = []
- array6
- array6.isEmpty
- array6 += ["m"]
- array6.insert("n", atIndex: 0)
- array6
- array6.removeAtIndex(0)
- array6
- array6.removeLast()
- array1[0]
- array1[1...2] = ["a","b","c"]
- array1[0...2] = ["a"]
-
- for (index,item) in enumerate(array1){
- println("index : \(index) value : \(item)")
- }
(1)初始化
(2)新增、修改、删除、查询
(3)遍历
- var dict1:Dictionary<String,String> = ["ak":"av","bk":"bv","ck":"cv"]
- var dict2:Dictionary<Int,String> = [1:"av",5:"bv",6:"cv"]
- dict1["ak"]
- dict1["bk"]
-
- dict2[5]
- dict2[6]
-
- dict2
-
- var dict3 = Dictionary<String,String>()
- var dict4 = [String:String]()
- dict4
-
- dict2 = [:]
-
- dict1.count
- dict1["ak"]! + "x"
- dict1["ak"] = "aav"
- dict1.updateValue("aaaav", forKey: "ak")
- dict1["dk"] = "dk"
- dict1["dk"] = nil
- dict1.removeValueForKey("dk")
-
- for (key,value) in dict1 {
- println("key \(key), value \(value)")
- }
-
- Array(dict1.keys)
- dict1.values
swift基础--数组、字典
原文:http://www.cnblogs.com/isItOk/p/4873164.html