IOS Creating your own blocks

// Here's a method that takes a block
- (void)doMathWithBlock:(int (^)(int, int))mathBlock {
    self.label.text = [NSString stringWithFormat:@"%d", mathBlock(3, 5)];
}

// Calling that method with a block
- (IBAction)buttonTapped:(id)sender {
    [self doMathWithBlock:^(int a, int b) {
        return a + b;
    }];
}

Comments

Popular posts from this blog

Java : Variables Declaring

SQL Self JOIN