How to sleep for few milliseconds in swift 2.2?

I think more elegant than usleep solution in current swift syntax is: Thread.sleep(forTimeInterval: 0.002)


use func usleep(_: useconds_t) -> Int32 (import Darwin or Foundation ...)

IMPORTANT: usleep() takes millionths of a second, so usleep(1000000) will sleep for 1 sec


usleep() takes millionths of a second

usleep(1000000) //will sleep for 1 second
usleep(2000) //will sleep for .002 seconds

OR

 let ms = 1000
 usleep(useconds_t(2 * ms)) //will sleep for 2 milliseconds (.002 seconds)

OR

let second: Double = 1000000
usleep(useconds_t(0.002 * second)) //will sleep for 2 milliseconds (.002 seconds)

Tags:

Uikit

Sleep

Swift