Last active
December 30, 2015 00:59
-
-
Save mmcbrear/7752966 to your computer and use it in GitHub Desktop.
Background download JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) loadJSON:(NSURL*)url | |
{ | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
NSData* data = [NSData dataWithContentsOfURL:url]; | |
[self performSelectorOnMainThread:@selector(fetchedData:) | |
withObject:data | |
waitUntilDone:YES]; | |
}); | |
} | |
- (void) fetchedData:(NSData *)data | |
{ | |
if(data == nil) | |
{ | |
NSLog(@"Handle JSON download error"); | |
return; | |
} | |
NSError *error = nil; | |
id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; | |
if(!error) | |
{ | |
// Process JSON | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment