请有人告诉我如何在swift 2.2中使用sleep()几毫秒?
while (true){ print("sleep for 0.002 seconds.") sleep(0.002) // not working }
但
while (true){ print("sleep for 2 seconds.") sleep(2) // working }
这是工作。
usleep()占用百万分之一秒
原文链接:https://www.f2er.com/swift/320222.htmlusleep(1000000) //will sleep for 1 second usleep(2000) //will sleep for .002 seconds
要么
let ms: UInt32 = 1000 usleep(2 * ms) //will sleep for 2 milliseconds (.002 seconds)
要么
let second: UInt32 = 1000000 usleep(UInt32(0.002) * second) //will sleep for 2 milliseconds (.002 seconds)