Wednesday, 7 October 2015

How to Use Completion Block In Ios/iphone

=> Here Work with returnType (.h above @interface declaration)

=> typedef void (^CompleteDiceRolling)(NSInteger diceValue);

    Declared With One Of the a @property for the block (.h)

    @property (copy, nonatomic) CompleteDiceRolling completeDiceRolling;

    Declared here One Of a Method with finishBlock (.h)

    - (void)getDiceValueAfterSpin:(void (^)(NSInteger diceValue))

     finishBlock;

=>  Use Periviose Method in .m file and commit finishBlock to @property
    declared before:-

    - (void)getDiceValueAfterSpin:(void (^)(NSInteger diceValue))

     finishBlock{
        self.completeDiceRolling = finishBlock;
    }

=>  Here Use completionBlock Pass Predefined variableType to it
    (Don't forget to check whether the completionBlock exists):-

    if( self.completeDiceRolling ){
        self.completeDiceRolling(self.dieValue);
    }

    => Finaly Use it With Work Completion Block.