您的位置:首页 > 移动开发 > Swift

swift 2

2015-12-22 11:21 381 查看
...

..<

func a(inout a) //by ref use &xx

Parameters passed to functions are constants by default, which means they can't be modified.

func incrementAndPrint(var value: Int) { //var 可修改,传值
value++
print(value)
}

Closure

var multiplyClosure: (Int, Int) -> Int

multiplyClosure = { (a: Int, b: Int) -> Int in
return a * b

}

multiplyClosure = { (a, b) in
a*b

}

multiplyClosure = {
$0 * $1 }

if you are using an optional type then you know you must handle the nil case

optional

let binding

Nil coalescing ??

计算属性可以用于类、结构体和枚举里,存储属性只能用于类和结构体

使用关键字 static 来定义值类型的类型属性,关键字 class 来为类(class)定义类型属性

@objc 可以让你的 Swift API 在 Objective-C
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: