39
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Swift] MainThreadで処理を実行する

Last updated at Posted at 2017-08-01

MainThreadで実行されているか確認

Thread.isMainThreadで確認する

if Thread.isMainThread {
    print("MainThreadです")
} else {
    print("MainThreadではない")
}

MainThreadで実行する方法

GCDを利用

Swift3.0

DispatchQueue.main.async {
    // メインスレッドで実行 UIの処理など
}

Objective-C

dispatch_async(dispatch_get_main_queue(), ^{
    // メインスレッドで実行 UIの処理など
});
39
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?