13
9

More than 3 years have passed since last update.

【Swift】処理をコンマn秒止める(遅延処理)

Posted at

どういうことか

// 1秒止める
sleep(1)

上記のコードで処理を1秒止めることができるが、例えば sleep(0.5) と書くとエラーになる。
sleep関数の引数は Uint32 で指定しなければならず、これは『32ビット符号なし整数』のことで……まあとにかく浮動小数点は指定できないのだ。

Thread.sleep

これでいける。

// 0.5秒止める
Thread.sleep(forTimeInterval: 0.5)
13
9
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
13
9