• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Creating an NSTimer subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Creating an NSTimer subclass
      • From: j o a r <email@hidden>
    • Re: Creating an NSTimer subclass
      • From: Mike Abdullah <email@hidden>
    • Re: Creating an NSTimer subclass
      • From: Jonathan del Strother <email@hidden>
  • Prev by Date: Re: Intercepting PDF print output
  • Next by Date: Re: How to traverse from one window to another
  • Previous by thread: Re: NSTableView, columns only (live)resize without data
  • Next by thread: Re: Creating an NSTimer subclass
  • Index(es):
    • Date
    • Thread