tags:

views:

108

answers:

4

What does the '^' mean in the code below?

@implementation AppController

- (IBAction) loadComposition:(id)sender
{
    void (^handler)(NSInteger);

    NSOpenPanel *panel = [NSOpenPanel openPanel];

    [panel setAllowedFileTypes:[NSArray arrayWithObjects: @"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?

+2  A: 

It is a block (a.k.a. closure), an extension of C created by Apple.

KennyTM
+3  A: 

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).

Marcelo Cantos
+1  A: 

It is a block, likely for use with Grand Central Dispatch.

Alex Reynolds
A: 

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.

Matt Gallagher