Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smalltalk blocks in Objective-c?

Does Objective-C support blocks "a la Smalltalk"?

In Smalltalk, blocks are similar to "closures" or "lambda-expressions" or "nameless functions" found in other languages.

like image 369
cfischer Avatar asked Oct 13 '10 18:10

cfischer


People also ask

What are blocks in Smalltalk?

Code blocks in Smalltalk are self-contained pieces of computation which can be activated by sending them the #value message or one of its variants. A Smalltalk block is Smalltalk's term for a closure. Blocks are instances of class BlockContext.

What is closure in Objective C?

A closure is said to escape a function when the closure is passed as an argument to the function, but is called after the function returns. When you declare a function that takes a closure as one of its parameters, you can write @escaping before the parameter's type to indicate that the closure is allowed to escape.


1 Answers

Yes: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html

Out of the box, they're only supported in the version of Objective-C 2.0 that comes with XCode 3.2 or later. This means you'll need Snow Leopard if you want to use the official build tools. A potential work-around for 10.5 is described here: http://thirdcog.eu/pwcblocks/#leoiphone

like image 194
Paul Baumgart Avatar answered Nov 02 '22 16:11

Paul Baumgart