Szymon Fortuna
Szymon Fortuna

Reputation: 400

How do I store one completion handler in a class so that all methods could use it?

Supposing I have a class with class methods only and within a method I have two NSURLSessionDataTask / NSURLSessionUploadTask instances which have a completion handler like this:

^(NSData *responseData, NSURLResponse *response, NSError *error){
//here parsing the response etc.    
}

which are 100% identical for both tasks.

What's the best way for me to create one completion handler in a class to use for both of them?

Upvotes: 0

Views: 72

Answers (1)

Vinzzz
Vinzzz

Reputation: 11724

Simply add a Class method that returns this completion handler, this way both other methods can call this one.

Upvotes: 4

Related Questions