If you really need to sleep, try usleepas suggested in @user3441734's answer.
However, you may wish to consider whether sleep is the best option: it is like a pause button, and the app will be frozen and unresponsive while it is running.
You may wish to use NSTimer.
//Declare the timer
var timer = NSTimer.scheduledTimerWithTimeInterval(0.002, target: self, selector: #selector(MyClass.update), userInfo: nil, repeats: true)
self, selector: "update", userInfo: nil, repeats: true)
func update() {
// Code here
}
DispatchQueue.global(qos: .background).async {
let second: Double = 1000000
usleep(useconds_t(0.002 * second))
print("Active after 0.002 sec, and doesn't block main")
DispatchQueue.main.async{
//do stuff in the main thread here
}
}