I\'m in a situation where need to call a class method from my view controller, have it do it\'s thing, but then perform some actions ONLY AFTER the class method has complete
I wrote a completionBlock for a class which will return the values of a dice after they have been shaked:
Define typedef with returnType (.h above @interface declaration)
typedef void (^CompleteDiceRolling)(NSInteger diceValue);
Define a @property for the block (.h)
@property (copy, nonatomic) CompleteDiceRolling completeDiceRolling;
Define a method with finishBlock (.h)
- (void)getDiceValueAfterSpin:(void (^)(NSInteger diceValue))finishBlock;
Insert previous defined method in .m file and commit finishBlock to @property defined before
- (void)getDiceValueAfterSpin:(void (^)(NSInteger diceValue))finishBlock{
self.completeDiceRolling = finishBlock;
}
To trigger completionBlock pass predefined variableType to it
(Don't forget to check whether the completionBlock exists)
if( self.completeDiceRolling ){
self.completeDiceRolling(self.dieValue);
}