Skip to content

Instantly share code, notes, and snippets.

@0x8badf00d
Forked from anonymous/gist:4277562
Created December 13, 2012 16:19
Show Gist options
  • Save 0x8badf00d/4277574 to your computer and use it in GitHub Desktop.
Save 0x8badf00d/4277574 to your computer and use it in GitHub Desktop.
AFJSONRequestOperation *operationJSON = [AFJSONRequestOperation
JSONRequestOperationWithRequest:requestJSON
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSMutableArray *results = [JSON valueForKey:@"results"];
// UPDATED CODE
for (id obj in [results valueForKey:@"value"]) {
if (![items containsObject:obj]) {
[items addObject:obj];
}
}
for (id obj2 in [results valueForKey:@"value2"]) {
if (![items2 containsObject:obj2]) {
[items2 addObject:obj2];
}
}
// END OF UPDATED CODE
/**
AFJSONOperation dispatches work to background thread. UIKit is not thread-safe . So dispatching work to main queue.
I am wrong here. AFJSONOperation dispatches success block onto main_queue. https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFJSONRequestOperation.m although the code below has no adverse affects.
*/
dispatch_async(dispatch_get_main_queue(),^{
[table reloadData];
[table scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
[table.pullToRefreshView stopAnimating];
});
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"%@", [error userInfo]);
}];
[operationJSON start];
// Commenting redundant reloadData
// [table reloadData];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment