Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the '^' in Objective-C

Tags:

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 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?

like image 950
Chris Paterson Avatar asked Apr 29 '10 09:04

Chris Paterson


People also ask

What is the at symbol in Objective-C?

The @ symbol is used in a few places in Objective-C, and basically it's a way to signal that whatever it's attached to is special to Objective-C and not part of regular C. This is important when the computer compiles Objective-C code.

What does @() mean in Objective-C?

In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals. '@' is used a lot in the objective-C world.

What is Objective-C vs C?

The main difference in C and Objective C is that C is a procedure programming language which doesn't support the concepts of objects and classes and Objective C is Object-oriented language which contains the concept of both procedural and object-oriented programming languages.

What is meant by Objective-C?

Objective-C is the primary programming language you use when writing software for OS X and iOS. It's a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime.


3 Answers

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

like image 55
Marcelo Cantos Avatar answered Nov 07 '22 21:11

Marcelo Cantos


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.

like image 39
Matt Gallagher Avatar answered Nov 07 '22 21:11

Matt Gallagher


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

like image 22
kennytm Avatar answered Nov 07 '22 21:11

kennytm