Block are piece of code introduced in ios 4.0. Block are used to make code cleaner and reduce dependency from delegates.
To use the block first we have to declare the block and then its definition.
Here is the syntax to declare to the Block.
return_type (^block_name)(param_type, param_type, ...)
example :
NSString(^myblockName)(NSString,NSString)
here is example how to define a Block:
NSString (^myblockName)(NSString,NSString)=^(NSString string1, NSString string2){
NSString *finalstring = [NSString stringWithFormat:@"%@,%@", string1, string2];
return finalstring;
}
so now if you have to call this Block:
NSString *finalString=myblockName(@"Block",@"is awsome");
Result : @"Block is awsome"
0 Comment(s)