NSNotification の通知は、別スレッドから呼ぶと、そのスレッドで実行されるので、通知を受けて UI を更新するような場合、都合が悪いことがあります。 (UIKit は Thread Safe でないため) そういうときは、下記のようにメインスレッドから通知するといいと思います。 NSNotification *notification = [NSNotification notificationWithName:NOTIFICATION object:self]; [notificationCenter performSelector:@selector(postNotification:) onThread:[NSThread mainThread] withObject:notification waitUntilDone:NO];
無為空間 むいむい(´ω`*) Entries NSOperationQueueとスレッドの関係 タグ: Objective-C Mac NSOperation NSOperationQueueを使ったプログラムをデバッグしていてふと気付いたのだが、NSOperationQueueは何もクソ真面目に「concurrentではない全てのoperationのために毎回スレッドを作っている」わけではないらしい。 例えば以下のコード。 @interface Operation : NSOperation { int number; } @property (nonatomic) int number; @end @implementation Operation @synthesize number; - (void)main { [NSThread sleepForTimeInterval:1]
無為空間 むいむい(´ω`*) Entries concurrent operationがstartするスレッド タグ: Objective-C NSOperation isConcurrentではないNSOperationのmainは新しく生成されたスレッドから呼ばれる。 では逆に、isConcurrentなNSOperationのstartはどのスレッドから呼ばれるのか。 ここでは、あまりこのような使い方をすることはないかもしれないが、「isConcurrentではないNSOperation」と「isConcurrentなNSOperation」を混ぜて使い、それらの各種メソッドが呼ばれるスレッドを調べてみる。 #pragma mark base class @interface OperationBase : NSOperation { NSUInteger number; } -
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く