运算符 swift

1nil聚合运算符 nil coalescing operator
a ?? b ==>a!=nil ? a! : b
要求:
1a是一个可选类型
2b必须和a解包后类型一致

var userNickName:String?
//let outputName:String = userNickName != nil ? userNickName! : "Guest"
let outputName:String = userNickName ?? "Guest"

2区间运算符
闭区间 [a,b] a...b
前闭后开 [a,b) a..<b

3for-in循环
for index in 1...10
{
}
//index默认是一个常量值

posted @ 2016-12-17 00:03  乱笙歌  阅读(147)  评论(0编辑  收藏  举报