Creating an NSTimer subclass
Creating an NSTimer subclass
- Subject: Creating an NSTimer subclass
- From: leenoori <email@hidden>
- Date: Thu, 9 Nov 2006 16:38:49 +0100
How do I create an NSTimer subclass?
The following example code shows how even an empty subclass can't be
initialized and throws this exception:
*** Uncaught exception: <NSInvalidArgumentException> ***
initialization method -
initWithFireDate:interval:target:selector:userInfo:repeats: cannot be
sent to an abstract object of class TimerSubclass: Create a concrete
instance!
/////////////// start example code ////////////////
#import <Foundation/Foundation.h>
@interface TimerSubclass : NSTimer
@end
@implementation TimerSubclass
@end
int main (int argc, const char * argv[])
{
[TimerSubclass scheduledTimerWithTimeInterval:1000
target:nil
selector:NULL
userInfo:nil
repeats:NO];
return 0;
}
//////////////// end example code /////////////////
Evidently, the issue is complicated by the fact that NSTimer might be
a class cluster under the hood, and it is toll-free bridged with
CFRunLoopTimer. Running class-dump on the Foundation framework reveals:
- NSTimer inherits from NSObject
- NSTimer has no instance variables (suspicious)
- There is a NSCFTimer class that inherits from NSTimer
- NSCFTimer also has no instance variables
- There is a NSCFTimer__ class that inherits from NSCFTimer
- NSCFTimer__ not only has no instance variables, but no methods either
- Testing shows that if you ask NSTimer for a timer, you get back a
NSCFTimer object (or at least something that claims to be a NSCFTimer)
I want to add a couple of methods to NSTimer, but I can't use a
category because I need to add a couple of instance variables as
well. So I want to find a way to subclass it.
Unlike some of the other class clusters (NSArray for instance) there
are no Apple docs on what methods need to be overridden (ie. what are
the "primitive" methods) to subclass NSTimer:
http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaFundamentals/CocoaObjects/chapter_3_section_9.html
Any one done this or have an idea of how to do it?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden