Re: NSTimer and call-by-reference
Re: NSTimer and call-by-reference
- Subject: Re: NSTimer and call-by-reference
- From: Jérôme Laurens <email@hidden>
- Date: Fri, 14 Feb 2003 10:18:48 +0100
Le vendredi, 14 fiv 2003, ` 09:40 Europe/Zurich, Colin Jackson a icrit :
And here is the full method:
- (void) timerForController:(NSString *)controller type:(NSString
*)type target:(id)target selector:(SEL)aSelector
repeats:(BOOL)doesRepeat timer:(NSTimer *)timer {
double delay;
if ([Defaults itemActive:type inController:controller]) {
delay = [Defaults getDoubleStateForKey:[[controller
stringByAppendingString:type]stringByAppendingString:@"Time"]];
if ([[Defaults getStringForKey:[[controller
stringByAppendingString:type]stringByAppendingString:@"Unit"]]
isEqualToString:@"Minutes"]) {
delay *= 60;
}
NSLog(@"about to check validity");
if ([timer isValid]) {
NSLog(@"Timer is valid");
if (!doesRepeat) {
NSLog(@"and doesn't repeat");
[timer invalidate];
timer = [NSTimer scheduledTimerWithTimeInterval:delay
target:target selector:aSelector userInfo:[controller
stringByAppendingString:type] repeats:doesRepeat];
timer = [timer retain];
}
}
else {
NSLog(@"Timer isn't valid");
NSLog([controller stringByAppendingString:type]);
timer = [NSTimer scheduledTimerWithTimeInterval:delay
target:target selector:aSelector userInfo:[controller
stringByAppendingString:type] repeats:doesRepeat];
timer = [timer retain];
As timer is a local variable, you will never get a chance to release it.
You should pass timer by reference replacing
(NSTimer *) timer
by
(NSTimer **) timerPtr
- (void) timerForController:(NSString *)controller type:(NSString
*)type target:(id)target selector:(SEL)aSelector
repeats:(BOOL)doesRepeat timer:(NSTimer **)timerPtr
BTW, I first thought that your function was returning a timer for the
controller. The following API seems to be more appropriate to your
method.
- (void) updateTimer: (NSTimer **) timerPtr forControllerKey: (NSString
*) key target: (id) target selector: (SEL) selector repeats: (BOOL)
yorn;
}
}
else {
if ([timer isValid])
[timer invalidate];
}
}
I hope this helps.
_______________________________________________
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.