Is there a similar setTimeout function in objective-c like in javascript? I dont want a sleep function.
I want to fire a "messa开发者_JAVA百科ge" after a period of time gone by but no locking up the device.
Try NSTimer.
As Calvin points you can use NSTimer class.
As an alternative you can use performSelector:withObject:afterDelay:
method to schedule method call after specific delay (note that it is not guaranteed that delay will be exactly you specified - it just will be not less than that value)
See NSObject's performSelector:withObject:afterDelay:. You can also use NSTimer — it's particularly useful for mimicking setInterval()
. And to execute arbitrary code instead of just sending a message, see Grand Central Dispatch's dispatch_after.
精彩评论