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.
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.
Yep, take this example:
[[myString componentsSeparatedByString:@"\n"] enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *line = (NSString *)obj;
//do what your going to do with line...
}];
Out of the box, they're only supported in the version of Objective-C 2.0 that comes with XCode 3.2. 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