Objective-C 函数调用后等待特定时间

Wait for specific time after function call in Objective-C

我有一个函数调用,调用后需要等待5秒。我不会等待使用 [NSThread sleepForTimeInterval:5] 或简单的 sleep(5),因为这是主线程上的 运行,我最终会阻塞我的整个应用程序。

需要的功能:

  1. 函数调用
  2. 睡 5 秒
  3. 继续处理其他函数

如何在 Objective-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
});