gpt4 book ai didi

objective-c - 如何在一行代码中写 `performSelectorInBackground: afterDelay:`?

转载 作者:行者123 更新时间:2023-12-03 13:14:03 24 4
gpt4 key购买 nike

performSelectorInBackground:中有performSelector: afterDelay:NSObject方法。如何将它们合并为一行代码?
也许以某种方式与NSTimer在一起?

最佳答案

您是否考虑过为此使用块?

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^(void){
//your code here
});

另外,如果看起来写的太多,则已经有一段代码了,开始输入“dispatch_after”,您会看到它。

关于objective-c - 如何在一行代码中写 `performSelectorInBackground: afterDelay:`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8818942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com