Objective-C Blocks

November 5, 2013

// Header (.h):
-(void)setHeight:(CGFloat)height tweenDuration:(float)duration onComplete:(void(^)())onCompleteBlock;

//Implementation (.m):
-(void)setHeight:(CGFloat)height tweenDuration:(float)duration onComplete:(void(^)())onCompleteBlock{
   ...
}

// Metohod call:
[cardBack setHeight:100.0 tweenDuration:0.5  onComplete:^void(){...}];

// Block assigned to variable:
void (^onCompleteBlock)() = ^void() {
   ...
};

// Metohod called with "block" variable:
[view setHeight:100.0 tweenDuration:0.5  onComplete:onCompleteBlock];

// Unsafa Unretained reference to self:
__unsafe_unretained typeof(self) weakSelf = self;

Tags: , ,