Re: Creating an NSTimer subclass
Re: Creating an NSTimer subclass
- Subject: Re: Creating an NSTimer subclass
- From: j o a r <email@hidden>
- Date: Fri, 10 Nov 2006 08:03:59 +0100
On 10 nov 2006, at 03.02, leenoori wrote:
How would you schedule such a timer, given that the method for
doing so is actually in NSRunLoop (addTimer:forMode:)? What happens
when you pass such a subclass to addTimer:forMode:? Class-dump
shows no instance variables on NSTimer or its subclasses, nor any
methods which look like candidates for use in adding a timer to a
run loop.
You would schedule the wrapped timer object, and not your object
instance.
There is another design decision to make: Should you [1] forward the
originating target+selector to the wrapped timer object, or should
you [2] use the wrapping custom class as the target, and have it
forward timer fire events to the originating target.
I would expect #2 to be the safe alternative if you don't want to
impose any restrictions on how your wrapping custom class is used -
for example if it will be exposed in a framework. Alternative #1 is
probably easier to implement, and would suffice in the vast majority
of cases - provided that you can influence how your class is used.
As an example of what could go wrong in #1: If the callback selector
is an action method, the timer is expected to be passed as the sender
parameter to that method (IIRC). If you allow the wrapped timer
object to call the target directly, the target would get access to
the wrapped timer object, leading to confusion and problems.
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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