swift 定义可选变量

19. December 2015 Swift 0

import Foundation

for index in 0…100{

//选择偶数,循环输出

if index%2==0

{

println(index)

}

}

var myName:String?=”lijian” //定义可选变量

myName = nil   //define null ,of course such as ‘nyname = “” ‘ is correct

if let name=myName{

//if myName is not null, the value is true,else is false

println(name)

}

强制解析 ! ,对于可选类型数据操作时候,需要强制解析,

可选绑定和隐式解析  var str3 = String1 = “swift”

溢出运算符 & ,可计算除数为零的情况     &+    &-    &*    &/    &%

特征相同运算符 ===

空合并运算符 ??    var content = say ?? words


Leave a Reply

Your email address will not be published. Required fields are marked *