Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Basic Block Syntax using Objective C

    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 215
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: