87
70

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 3 以降での遅延実行(Swift 2で言うdispatch_after)

Last updated at Posted at 2016-11-12

Swift 3 からはこう書けるようになった。
追記:Swift 4.x、Swift 5.x でも次の書式で動くよ!

// to run something in 0.1 seconds

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
    // your code here
}

詳細は http://stackoverflow.com/questions/37801436/how-do-i-write-dispatch-after-gcd-in-swift-3 を参照。

ちなみに、Swift 2 まではこんな感じだった。

var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC))) 
dispatch_after(dispatchTime, dispatch_get_main_queue(), { 
    // your function here 
})
87
70
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
87
70

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?