Swfit支持Unicode编码的字符
/*-------我是帅气的分割线--------*/
//var names: Array<String> = ["蒙牛","伊利"]
//var names1: String[] = ["蒙牛","伊利"]
var names = ["蒙牛","伊利",32] //OC中数组
var names1: NSArray = ["蒙牛","伊利",32]
var newNames = names.arrayByAddingObject("哇哈哈")
var name1 = ["蒙牛","伊利"]
/*
let name1 = ["蒙牛","伊利"]
name[0] = "哈哈" // 即使数组是不可变的,但是依然可以改变值
*/
name1 += ["风采","名家"]
name1.append("帅爆")
println("\(name1)") //打印:[蒙牛, 伊利, 风采, 名家, 帅爆]
name1[3] = "黑河"
println("\(name1)") //打印:[蒙牛, 伊利, 风采, 黑河, 帅爆]
name1[2...3] = ["小傻","哟西"]
println("\(name1)") //打印:蒙牛, 伊利, 小傻, 哟西, 帅爆]
name1[2..3] = ["小傻","哟西"]
println("\(name1)") //打印:[蒙牛, 伊利, 小傻, 哟西, 哟西, 帅爆]
for (index, value) in enumerate(name1){
println("index = \(index) value = \(value)") //打印索引和值
}
/*-------我是帅气的分割线--------*/
var sexDic: Dictionary<String,String> = ["公牛":"公","母牛":"母"] //字典类型: Dictionary<KeyType,ValueType>
println("sexDic = \(sexDic)") // 打印:sexDic = [公牛: 公, 母牛: 母]
for (key, value) in sexDic{
println("index = \(key) value = \(value)") //打印键值
}
//拿到自己想要的,不要的变为"_"
for (_, value) in sexDic{ // 如果想忽略某个值,直接在对应的位置加上"_"
println(" value = \(value)") //打印键值
}
sexDic["小孔"] = "男" // 如果字典中不存在这个键,则会创建一个新的键值对
println("sexDic = \(sexDic)") // 打印:sexDic = [小孔: 男, 公牛: 公, 母牛: 母]
sexDic["小孔"] = "女" // 如果字典中存在这个键,则会创建一个更新的键值对
println("sexDic = \(sexDic)") // sexDic = [小孔: 女, 公牛: 公, 母牛: 母]
let ox = sexDic["公牛"]
println("公牛 sex= \(ox)")