views:

62

answers:

2

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?

+6  A: 

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.

bbum
I was using an array to store timers and other objects at the same time... I've changed it, it wasn't a very good idea to start with. :) thanks.
Nano8Blazex
Excellent. We all succumb to the siren call of über-dynamism at some point in our programming life.
bbum
+2  A: 

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.

Jonathan Grynspan
That explains it. Thanks.
Nano8Blazex