I've got a function downloading something from the internet. Then it maps the items and returns everything to the controller. The problem is that there may be a lot of items (facebook don't let to divide them) and i have to map them in the background. However the user can quit the controller already and i don't know how to check if my success()
owner still exists.
Is it a good solution to put the mapping in the dispatch at all...?
Call:
[[MyHTTPClient sharedInstance] getSomethingWithAbc:abc successBlock:^{
[self reloadMyView];
} failureBlock:^(NSError *error) {
//nothing atm
}];
where:
@interface MyHTTPClient : AFHTTPClient
+ (OHTTPClient *)sharedInstance;
- (void)getSomethingWithAbc:(ABC *)abc successBlock:(void (^)())success failureBlock:(void (^)(NSError *error))failure;
Method implementation:
- (void)getSomethingWithAbc:(ABC *)abc successBlock:(void (^)())success failureBlock:(void (^)(NSError *error))failure {
// request something from facebook API, wait for response then run:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// here map these items - there may be a lot of them so i have to do it in background
dispatch_async(dispatch_get_main_queue(), ^{
success(); // this may call a function from controller that does not exist already
});
}