Difference between block (Objective-C) and closure (Swift) in iOS

前端 未结 3 854
北荒
北荒 2020-12-13 00:02

In tutorials it\'s written that functionally both are same even closure is more easier then block and its avoided the complexity of block and memory management, I\'ve gone t

3条回答
  •  孤城傲影
    2020-12-13 00:40

    To show an actual code example of the differences:

    This does compile:

    let x : @convention(swift) (inout Int) -> ()
    

    This does not:

    let y : @convention(block) (inout Int) -> ()
    

    with the error (inout Int) -> () is not representable in Objective-C

提交回复
热议问题