(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