Re: Creating an NSTimer subclass
Re: Creating an NSTimer subclass
- Subject: Re: Creating an NSTimer subclass
- From: Mike Abdullah <email@hidden>
- Date: Fri, 10 Nov 2006 10:02:25 +0000
Perhaps it would help a little more if you explained what the purpose
of this timer is.
Mike.
On 10 Nov 2006, at 07:03, j o a r wrote:
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
_______________________________________________
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