对 NSCFTimer 感到困惑...它是什么?
有人能告诉我 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSCFTimer
是 Foundation 和 CoreFoundation 框架的实现细节。它是 NSTimer 的子类,因此 isKindOfClass: 可以正常工作。但它确实引出了一个问题,即为什么您可能会引用一个可能是也可能不是 Timer 的对象。计时器的唯一来源是您的创建或框架内定义良好的方法。因此,这种不确定性是非典型的,并且通常表明存在潜在的设计问题。
NSCFTimer
is an implementation detail of the Foundation and CoreFoundation frameworks. It is a subclass ofNSTimer
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.
bbum 说得很好,但更直白一点:据你所知,
NSCFTimer
与NSTimer
是一样的,你不必担心它。 :)技术原因:
NSTimer
与CFRunLoopTimer
是免费桥接的。当您实例化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 asNSTimer
, and you needn't worry about it. :)The technical reason:
NSTimer
is toll-free bridged withCFRunLoopTimer
. When you instantiateNSTimer
, the code in that class replaces your instance with an instance of the Core Foundation opaque C typeCFRunLoopTimer
.CFRunLoopTimer
identifies itself to the Objective-C runtime as an instance of the classNSCFTimer
, so the class of an instance ofNSTimer
will be reported asNSCFTimer
.For more information about toll-free bridging, Core Foundation, and how often you use both without even knowing it, see Apple's documentation.