1

I have a method that basically uses this:

-(void)myMethodwithDuration:(NSTimeInterval)time{
[UIView animateWithDuration:time
                     animations:^{
                          // do thing here
                     }
                     completion:^(BOOL finished){
                          //do completion stuff here
                     }
     ];

What I don't know how to do is to write/package up a parameter so that I can write the code I want to execute, and then simply pass it into the method like I do with time.

Any help appreciated. Thanks

user339946
  • 5,961
  • 9
  • 52
  • 97
  • 1
    This is all covered in Apple's [Blocks Programming Topic](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40007502) document. – rmaddy Jan 23 '15 at 16:52
  • http://stackoverflow.com/questions/16324095/custom-completion-block-for-my-own-method – Suhas Arvind Patil Feb 25 '16 at 10:27

1 Answers1

1

To accept a block with void return value, and a BOOL param:

- (void)myMethodWithBlock:(void (^)(BOOL someCoolBool))block {
    if (block) {
        block(YES);
    }
}

To call it:

[self myMethodWithBlock:^(BOOL someCoolBool) {
    if (hasParams) {
        //....
    }
}];

Quick reference: FBS.com

Oscar Swanros
  • 19,767
  • 5
  • 32
  • 48