@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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With