Skip to content

Instantly share code, notes, and snippets.

@simme
Created April 20, 2011 12:59
Show Gist options
  • Select an option

  • Save simme/931269 to your computer and use it in GitHub Desktop.

Select an option

Save simme/931269 to your computer and use it in GitHub Desktop.
Loading with NSOperation instead
- (id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Load the data
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSOperationQueue *main = [NSOperationQueue mainQueue];
NSBlockOperation *fetchStreamOperation = [[NSBlockOperation alloc] init];
[fetchStreamOperation addExecutionBlock:^{
NSLog(@"Getting data");
NSURL *publicTimeline = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/public_timeline.json"];
NSError *error = nil;
NSData *tweetData = [NSData dataWithContentsOfURL:publicTimeline options:0 error:&error];
_tweets = [[tweetData objectFromJSONData] retain];
[main addOperationWithBlock:^{
[self.tableView reloadData];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}];
//[self performSelectorOnMainThread:@selector(reloadData:) withObject:tweets waitUntilDone:NO];
}];
[queue addOperation:fetchStreamOperation];
[queue release];
self.title = @"Tweetoramah";
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment