Re: NSTimer and call-by-reference
Re: NSTimer and call-by-reference
- Subject: Re: NSTimer and call-by-reference
- From: Colin Jackson <email@hidden>
- Date: Tue, 18 Feb 2003 20:20:07 +0000
I only just got a chance to give this a go and I'm afraid it hasn't
helped. In fact it is exactly the same as it was before but now I get
lots of warnings saying things like:
TimerManager.m:49: warning: passing arg 6 of
`timerForController:type:target:selector:repeats:timer:' from
incompatible pointer type
TimerManager.m:102: warning: invalid receiver type `NSTimer **'
I know it might be my fault. This is uncharted territory for me.
Colin
On Friday, February 14, 2003, at 09:18 am, Jirtme Laurens wrote:
>
>
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.