Blocks(Chapter 3 of Advanced Mac OS X Programming)
#import <Foundation/Foundation.h>int main (int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSArray *array = ;
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"object at index %lu is %@", idx, obj);
}];
NSIndexSet *indices = [array indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
NSRange match = ;
if (match.location == NSNotFound)
{
return NO;
}
else
{
return YES;
}
}];
NSLog(@"%@", indices);
}
return 0;
}
页:
[1]