Xcode Swift Ios App: Adding delay Xcode Swift Ios App: Adding delay xcode xcode

Xcode Swift Ios App: Adding delay


If you only need a sleep function, just use

NSThread.sleepForTimeInterval(1)


Use usleep which takes an int in microseconds. (i.e. 1,000,000 microseconds is equivalent to 1 second) So for 0.1s use:

       // Sleep for 0.1s       usleep(100000) 

Recommend to use in a background thread. You certainly don't want to be doing this on the main UI Thread!


You can use NSTimer for that, firstly you implement NSTimer and you add duration time 1.0 second or what ever want then, pass the time NSTimer call its function and you change questions to another