Tutorial by Examples

- (void)methodWithBlock:(returnType (^)(paramType1, paramType2, ...))name;
A block that performs addition of two double precision numbers, assigned to variable addition: double (^addition)(double, double) = ^double(double first, double second){ return first + second; }; The block can be subsequently called like so: double result = addition(1.0, 2.0); // result =...
@interface MyObject : MySuperclass @property (copy) void (^blockProperty)(NSString *string); @end When assigning, since self retains blockProperty, block should not contain a strong reference to self. Those mutual strong references are called a "retain cycle" and will prevent the...
typedef double (^Operation)(double first, double second); If you declare a block type as a typedef, you can then use the new type name instead of the full description of the arguments and return values. This defines Operation as a block that takes two doubles and returns a double. The type can b...
returnType (^blockName)(parameterType1, parameterType2, ...) = ^returnType(argument1, argument2, ...) {...}; float (^square)(float) = ^(float x) {return x*x;}; square(5); // resolves to 25 square(-7); // resolves to 49 Here's an example with no return and no parameters: NSMutableDicti...

Page 1 of 1