类型别名
(type aliases):给现有类型定义另一个名字。使用 typealias 关键字来定义类型别名。
当你想要给现有类型起一个更有意义的名字时,类型别名非常有用。
给 Int
起 别名
typealias MyInt = Int
let num: MyInt = MyInt.max
print(num)
给 block 起 别名
typealias MyBlock = () -> ()
let myBlock: MyBlock = {
print("this is block")
}
myBlock() // this is block
typealias
关键字可以对所有类型起别名,比如 Float、Double、String 、Cocoa-Touch 类、Cocoa 类等等