AFNetworking Return value from async task iOS

好久不见. 提交于 2019-12-06 14:04:25

You should try to implement the method like this:

+ (void) getTimeline:(NSString*)val success:(void (^)(id))success failure:(void (^)(NSError *))failure;

And use it like this:

[MyClass getTimeline:nil
               success:^(id result) {} failure:^(NSError *error) {} 

The success block will have the returned value if any!

Anything more? :)

You can't return an value from that block, as it's asynchronous and continues to run while other tasks are going on.

The correct way to handle this is to call the method that deals with this data from within the block and pass it the array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!