What is the '^' in Objective-C
What does the '^' mean in the code below?
@implementation AppController
- (IBAction) loadComposition:(id)sender
{
void (^handler)(NSInteger);
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowedFileTypes:[NSArray a开发者_如何学CrrayWithObjects: @"qtz", nil]];
handler = ^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
NSString *filePath = [[[panel URLs] objectAtIndex:0] path];
if (![qcView loadCompositionFromFile:filePath]) {
NSLog(@"Could not load composition");
}
}
};
[panel beginSheetModalForWindow:qcWindow completionHandler:handler];
}
@end
=== I've searched and searched - is it some sort of particular reference to memory?
Read up on it here. It's a "Block object", which is basically a lambda form, and was introduced to support Snow Leopard's GCD (Grand Central Dispatch).
Small aside: the '^' character (caret or circumflex character) has a different meaning when used as a binary operator:
a ^ b
means a XOR b. XOR (aka exclusive OR) is a binary arithmetic operation where the the result has a 1 in any bit position where either a or b had a 1 but not both.
It is a block (a.k.a. closure), an extension of C created by Apple.
It is a block, likely for use with Grand Central Dispatch.
精彩评论