Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a custom method with completion block [duplicate]

Possible Duplicate:
Implementing a method taking a block to use as callback

I couldn't find any clear explanation about how to implement a method that executes a completion block.

I know that NSOperation can be subclasses and used with calling setCompletionBlock: . Anyone knows if this is possible just by implementing in the m. file?

like image 467
Kaan Dedeoglu Avatar asked Apr 28 '12 05:04

Kaan Dedeoglu


People also ask

How do you create a completion block in Objective C?

For example, you might use the custom completion block type you just saw to create an instance variable. MyCustomCompletionBlock completion = ^(BOOL finished){ NSLog(@"completed"); }; You can then use that block as an argument, for example: [self performWithCompletion:completion];

What is completion block?

The completion block should be used to notify interested objects that the work is complete or perform other tasks that might be related to, but not part of, the operation's actual task. A finished operation may finish either because it was cancelled or because it successfully completed its task.


1 Answers

You may not believe it, but there is a Code Samurai Article which covers the exact ground of your question! About a third of the way down, they subclass NSOperation with an example completion block.

like image 82
CodaFi Avatar answered Dec 04 '22 18:12

CodaFi