HackU HackU - 1 year ago 238
iOS Question

Objective-C the ^ operator

I'm a newbie in Objective C and trying to figure out what does the ^ operator? While exploring some source code i saw next construction:

dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20.f, 13.f), NO, 0.0f);

[[UIColor blackColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 20, 1)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 5, 20, 1)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 10, 20, 1)] fill];

[[UIColor whiteColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 1, 20, 2)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 6, 20, 2)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 11, 20, 2)] fill];

defaultImage = UIGraphicsGetImageFromCurrentImageContext();


And I'd like to know what is the ^?

Answer Source

The ^ indicated the start of a block definition within Objective-C.

Have a look in here: http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/bxGettingStarted.html#//apple_ref/doc/uid/TP40007502-CH7-SW1

Note that in this context, the ^ is not an operator, it is part of the syntax of Objective-C @Mike's down-voted answer is strictly the correct definition of the "^ operator"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download