对 NSCFTimer 感到困惑...它是什么?

发布于 2024-09-08 10:00:21 字数 157 浏览 3 评论 0原文

有人能告诉我 NSCFTimer 到底是什么吗?当我向 NSTimer 询问计时器时我得到了它。 我的问题是,我试图检查一个对象(应该是 NSTimer,请注意“据说”这个词,这就是我检查的原因)是否是 NSTimer 类的对象,它似乎不起作用。这个“NSCFTimer”会以任何方式阻碍这个过程吗?

Could someone tell me what exactly NSCFTimer is? I get it when I ask NSTimer for a timer.
My problem is that I'm trying to check if an object (supposedly an NSTimer, note the word "supposedly" which is why I'm checking) is an object of class NSTimer, it doesn't seem to work. Does this "NSCFTimer" in any way... hinder the process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混浊又暗下来 2024-09-15 10:00:21

NSCFTimer 是 Foundation 和 CoreFoundation 框架的实现细节。它是 NSTimer 的子类,因此 isKindOfClass: 可以正常工作。

但它确实引出了一个问题,即为什么您可能会引用一个可能是也可能不是 Timer 的对象。计时器的唯一来源是您的创建或框架内定义良好的方法。因此,这种不确定性是非典型的,并且通常表明存在潜在的设计问题。

NSCFTimer is an implementation detail of the Foundation and CoreFoundation frameworks. It is a subclass of NSTimer and, thus, isKindOfClass: will work just fine.

It does beg the question, though, of why you might have a reference to an object that might or might not be a Timer. The only sources of timers are either of your creation or well defined methods within the frameworks. Thus, such uncertainty is both atypical and oft indicates an underlying design problem.

善良天后 2024-09-15 10:00:21

bbum 说得很好,但更直白一点:据你所知,NSCFTimerNSTimer 是一样的,你不必担心它。 :)

技术原因: NSTimerCFRunLoopTimer 是免费桥接的。当您实例化 NSTimer 时,该类中的代码会将您的实例替换为 Core Foundation 不透明 C 类型 CFRunLoopTimer 的实例。 CFRunLoopTimer 在 Objective-C 运行时将自身标识为类 NSCFTimer 的实例,因此 NSTimer 实例的类将被报告为NSCFTimer

有关免费桥接、Core Foundation 以及您在不知情的情况下使用两者的频率的更多信息,请参阅 Apple文档

bbum put it quite nicely, but to be more blunt: as far as you need to know, NSCFTimer is the same thing as NSTimer, and you needn't worry about it. :)

The technical reason: NSTimer is toll-free bridged with CFRunLoopTimer. When you instantiate NSTimer, the code in that class replaces your instance with an instance of the Core Foundation opaque C type CFRunLoopTimer. CFRunLoopTimer identifies itself to the Objective-C runtime as an instance of the class NSCFTimer, so the class of an instance of NSTimer will be reported as NSCFTimer.

For more information about toll-free bridging, Core Foundation, and how often you use both without even knowing it, see Apple's documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文