I'm working with the Evernote API, and I'm not sure how to properly manage working with blocks without my code being incredibly messy and spewed all over the place.
The API includes methods to this style:
[object doSomethingWithSuccess:^(NSObject *anotherObject) {
NSLog(@"success!");
} failure:(NSError *error) {
NSLog(@"failure!");
}
After that, I have to run another similar method based on the success of that, and then another similar one based on that.
I also have a problem where I really just want to run a method which does something and then returns after however long it takes, but I can't return from inside the block.
How do people deal with this?
An example:
In some scenarios, I want to create a notebook, and then do something else. The 'something else' is different each time. I would never put the code to connect in With standard code, i'd run a method:
[self connect];
//Do the 'something else'
But in this situation, I can't even think of a way that I could do this, other than copy and pasting the code inside [self connect] to everywhere i want to connect, and then running the next piece of code in the completion handler.
To run other things based on success, you just call them from within the block - if it's another operation that takes another block, usually people just nest them.
Instead of returning from within the block, you have to create another method that you call when the block is done.