我有一个函数调用,我打电话后需要等待5秒钟。我不等待使用[NSThread sleepForTimeInterval:5]
或简单的sleep(5)
,因为它在主线程上运行,我将最终阻止我的整个应用程序。
所需功能
function call
sleep for 5 secs
continue processing other functions
关于如何在目标C上做到这一点的任何想法?
dispatch_after怎么样?
https://developer.apple.com/documentation/dispatch/1452876-dispatch_after
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// throw your call to other functions in here
});