字符串
let str = "1234"
let wirth = 5678
let strwidth = str + String(wirth)
let strwidth1 = "我又\(strwidth)xxx"
数组
var array = ["a","b","c"]
array.first //第一个元素
array.last //最后一个元素
array.contains("9") //是否存在该元素
array.contains(3)
let bool1 = arr1 == arr2 //两数组是否相等
array += array //增
array.append ("增")
array.insert("c", at: 2) //插入 位置
array[0] = "aaa" //替换
array.remove(at: 1) //删除
print(array)
let emptyArr = [String]() //空数组
emptyArr1 =[] //空数组
//遍历数组
for item in array {
}
字典
var dic = ["A":"a",
"B":"b",
]
for key in dic.keys {
print(key)
}
for (key,value) in dic {
print("key:\(key) -- value:\(value)")
}
dic["A"] = "Aaaa"
print(dic)
let emptyDic = [String:Float]() //空字典
emptyDic1 =[:]
网友评论