Created
August 10, 2012 15:54
-
-
Save tatsuro-ueda/3315194 to your computer and use it in GitHub Desktop.
スレッドの使い方メモ
This file contains 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
/* | |
* 別スレッドを立てる | |
*/ | |
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