Skip to content

Instantly share code, notes, and snippets.

@tatsuro-ueda
Created August 10, 2012 15:54
Show Gist options
  • Save tatsuro-ueda/3315194 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3315194 to your computer and use it in GitHub Desktop.
スレッドの使い方メモ
/*
* 別スレッドを立てる
*/
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperationWithBlock:^{
// 何かする
}];
/*
* メインスレッドに戻す
*/
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[mainQueue addOperationWithBlock:^{
// テーブル更新
[alertView dismissWithClickedButtonIndex:0 animated:YES];
[self.tableView reloadData];
}];
/*
* スレッドが終了するのを待つ
*/
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
ssURL = [NSURL URLWithString:[JSON valueForKeyPath:@"screenshot"]];
[self currentEntry].ogImageURL = ssURL;
} failure:nil];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation: operation];
[queue waitUntilAllOperationsAreFinished];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment