Blocks in Objective-C @techytube
Blocks in Objective-C  @techytube
Uploaded October 2012 | Updated September 2026, 2 weeks ago
Subscribe to our channel here for notifications on new video trainings. For more videos on technology, visit our website at http://www.techytube.com.
By pavel@techytube, for more from this author visit:
techytube.com/author/pavel

Block objects provide a way for you to create an ad hoc function body as an expression in C, and C-derived languages such as Objective-C and C++. In other languages and environments, a block object is sometimes also called a "closure". Here, they are typically referred as "blocks", unless there is scope for confusion with the standard C term for a block of code.

You use the ^ operator to declare a block variable and to indicate the beginning of a block literal. The body of the block itself is contained within {}, as shown in this example (as usual with C, ; indicates the end of the statement):

int multiplier = 7;

int (^myBlock)(int) = ^(int num) {
return num * multiplier;
};

Notice that the block is able to make use of variables from the same scope in which it was defined.

If you declare a block as a variable, you can then use it just as you would a function:

int multiplier = 5;

int (^myBlock)(int) = ^(int num) {
return num * multiplier;
};

int result = myBlock(4);

NSLog(@"result = %d", result); // will output "result = 20"

You can find more about blocks on the following web page:

developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html
Blocks in Objective-CWindows 8 Development - Saving Session StateWindows 8 User Interface OverviewWindows 8 Development - Edit Static Text PropertyWindows 8 Development - XAML DefaultViewModel BindingWindows 8 Development - Data Binding Grid TitleManaging Service On Linux Server Part 1 Of 2ASP.NET Razor SyntaxWindows 8 Development - Javascript Life CycleSonicWall - Configure Standard PortsLinux File And Directory Permission - Part 2Explaining different application types in iOS
techytube |

Blocks in Objective-C

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER