2013/07/06

[iOS][Objective-C]_WebThreadLockFromAnyThreadについて

dispatch_async内で、UITextViewのtextプロパティーにアクセスしたら下のような警告が出力された。

void _WebThreadLockFromAnyThread(bool), 0x8547fb0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
これ、考えみると当然と言えば、当然なんだけど、UIKItの各要素のアクセスは、メインスレッドじゃないといけないので、
dispatch_async(main_queue, ^{

});
の中だとおkなんだけど、
dispatch_async(dispatch_queue_create("hoge", NULL);, ^{


});
の中だとNG.

だから、メインスレッド以外のスレッドでUITextViewのtextプロパティを使いたい場合は、
NSString *foo = uiTextView.text;
dispatch_async(dispatch_queue_create("hoge", NULL);, ^{
    //fooを使った処理
});
って書けばいいんですな。

0 コメント:

コメントを投稿