objective c - Returning method object from inside block -
i wondering how next correctly: have method homecoming nsdata
object. gets nsdata
object uidocument
. nsdata
object can large, want create sure loaded before response starts. hence homecoming value of method within block itself. this:
- (nsdata*)getmydata { myuidocument *doc = [[myuidocument alloc] initwithfileurl:fileurl]; [doc openwithcompletionhandler:^(bool success) { if (success) { homecoming doc.myresponsedata; // homecoming method not block } }]; }
this causes error because return
apparently refers block
's return
.
how can accomplish without having create thread blocking wait/while loop?
thanks.
you can't. encompass fact you're trying asynchronous , add together completion block parameter getmydata
method called when inner completion handler called. (and remove return
method signature):
- (void)getmydatawithcompletion:(void(^)(nsdata *data))completion { myuidocument *doc = [[myuidocument alloc] initwithfileurl:fileurl]; [doc openwithcompletionhandler:^(bool success) { completion((success ? doc.myresponsedata : nil)); }]; }
objective-c ios7 block uidocument completionhandler
No comments:
Post a Comment