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

Sujay picture Sujay · Oct 15, 2014 · Viewed 21.3k times · Source

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 through many tutorials but except these I'm not getting the difference between swift's "closure" and Objective-C "block".

Answer

GoZoner picture GoZoner · Oct 15, 2014

Excerpt From: Apple Inc. “Using Swift with Cocoa and Objective-C.” iBooks:

“Swift closures and Objective-C blocks are compatible, so you can pass Swift closures to Objective-C methods that expect blocks. Swift closures and functions have the same type, so you can even pass the name of a Swift function.

Closures have similar capture semantics as blocks but differ in one key way: Variables are mutable rather than copied. In other words, the behavior of __block in Objective-C is the default behavior for variables in Swift.”