-[NSString stringWithContentsOfURL:encoding:error:] を非同期にしようとしましたが、バックグラウンド スレッドから非同期で実行しました。
__block NSString *result;
dispatch_queue_t currentQueue = dispatch_get_current_queue();
void (^doneBlock)(void) = ^{
printf("done! %s",[result UTF8String]);
};
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
result = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"] encoding:NSUTF8StringEncoding error:nil];
dispatch_sync(currentQueue, ^{
doneBlock();
});
});
正常に動作し、最も重要なのは非同期です。
私の質問は、これを行うのが安全かどうか、またはスレッドの問題などがある可能性があるかどうかです.
前もって感謝します :)