gpt4 book ai didi

iphone - 如何重写 [NSRunLoop runUntilDate :] to GCD code?

转载 作者:行者123 更新时间:2023-11-28 23:06:34 24 4
gpt4 key购买 nike

出于好奇,我正在尝试重写以下代码

// show HUD (with animation)
[SVProgressHUD showWithStatus:@"loading..."];

// wait for HUD to safely finish showing its animation
// (loading HUD will be visible for 1 sec)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]

// dismiss HUD
// (dismiss HUD will be visible for 2 sec)
[SVProgressHUD dismissWithSuccess:@"finished!" afterDelay:2];

使用 Grand Central Dispatch 进入代码。

我尝试使用 dispatch_source_t、dispatch_semaphore_t 和 dispatch_after,但效果不是很好:(我需要你的帮助!

请注意,我不想用任何 block 包装 SVProgressHUD 的方法!

最佳答案

你真的不能。或者,您也可以,但最终只是包装 NSRunLoop 内容本身需要大量工作。

在 iOS 和 Mac OS X 的上下文中,主事件循环是一个运行循环,模态面板、HUD 等都是围绕该细节设计的。

您显示的代码是一个嵌套运行循环。您实际上是在外循环内的子循环中运行主运行循环,该外循环也由主运行循环维护! (如果您要在内部循环中触发的操作方法上设置断点,您会在回溯中明白我的意思)。

关于iphone - 如何重写 [NSRunLoop runUntilDate :] to GCD code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205260/

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