1

I'm having trouble creating completion blocks. I found the solution here . It works for me, but I don't quite understand this. Now I'm still confused and don't know how to write a block myself. Are there any batter ways to understand blocks? Also, when should I use it? Is there anything that can replace blocks?

Should I create it as a property? Method perimeter? Do they have difference in efficiency?

Thank you!

Community
  • 1
  • 1
NSError
  • 175
  • 1
  • 9

1 Answers1

2

check out http://fuckingblocksyntax.com for syntax. For personal choice I like to return value and error in the completion block (similar to iOS framework pattern) As an example;

declaration

- (void)fetchStuff:(void (^)(id value,NSError *error))completion;

calling the function

// async fetch
[object fetchStuff:^(id value, NSError *error) {
    // do stuff with value
}];
cekisakurek
  • 2,474
  • 2
  • 17
  • 28