个人理解swift中的闭包就是oc中的block
[1]声明一个闭包:
var closureName: (ParameterTypes) -> (ReturnType)
例如:
private var doSomethingHandler: (NSError?) -> (Void)
[2]声明一个可为空的闭包:
var closureName: ((ParameterTypes) -> (ReturnType))?
例如:
private var doSomethingHandler: ((NSError?) -> (Void))?
[3]给闭包取别名:
typealias ClosureType = (ParameterTypes) -> (ReturnType)
例如:
typealias doSomethingHandler = (NSError?) -> (Void)
网友评论