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.
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
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...
}];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.