Re: NSTimer and call-by-reference
Re: NSTimer and call-by-reference
- Subject: Re: NSTimer and call-by-reference
- From: Shawn Erickson <email@hidden>
- Date: Thu, 13 Feb 2003 18:27:04 -0800
On Thursday, February 13, 2003, at 04:44 AM, Colin Jackson wrote:
I have a method with the following signature:
- (void) timerForController:(NSString *)controller type:(NSString
*)type target:(id)target selector:(SEL)aSelector
repeats:(BOOL)doesRepeat timer:(NSTimer *)timer
For some reason, whenever I call this method, whatever timer is passed
gets duplicated. ie, the method checks that the timer valid and is
still doing the right thing according to current circumstances (I won't
bore you with them), then recreates the timer if it is not.
When I check if the timer is valid, it always returns no. Then it
creates a new timer so I get lots of events firing. It looks like the
NSTimer isn't being called-by-reference properly.
By the way, this works when I use the same code directly (instead of
inside a method). Its just that I need to have 8 timers which do
pretty much the same thing so I don't want to have to inline code for
each of them.
Not sure we can help much with knowing what the code inside the method
looks like.
It sounds like someplace the method is making an incorrect decision
about the timer and is deciding to create a new instance when is really
shouldn't be. Possibly a retain issue or accidental allocating a new
timer when attempting to define a temporary variable?
All object communication happens by messages and it doesn't get changed
by the fact that it is inside an arbitrary method or not. Also all
objects are referenced by pointers (you cannot create an object on the
stack in Objective-C) so going across a method cannot affect this
(unless you are not passing down what you think you are passing down).
-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.