ios - Mixing Blocks and Delegates in Objective-C -
this question has answer here:
is possible run block when delegate receives message?
for example, if had framework took void block parameter (we'll call "success" block), , using nsurlconnection delegate stuff method arguments, when receive response webpage, how can call "success" block passed in method parameters?
this really hard me explain, , don't have code this, can clarify if have questions.
you absolutely can. how all completion handlers / callbacks work. in fact, block for.
to take simple example, consider nsurlconnection class method:
+ (void)sendasynchronousrequest:(nsurlrequest *)request queue:(nsoperationqueue *)queue completionhandler:(void (^)(nsurlresponse *response, nsdata *data, nserror *connectionerror))handler
for third parameter, pass block. , when request over, time in future, nsurlconnection do? calls block.
so, can same nsurlconnection doing. can write method takes block, hold on block, perhaps takes time, , later call block.
Comments
Post a Comment