Help us understand the problem. What is going on with this article?

Swift 3 以降での遅延実行(Swift 2で言うdispatch_after)

More than 1 year has passed since last update.

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

詳細は を参照。

ちなみに、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 
ドラムも叩けるプログラマです。iPhoneアプリ、Androidアプリ、mixiアプリを仕事/趣味で作ってます。主な作品 →
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away