Re : Newbie Q : Not-so-simple encoding&decoding example
Re : Newbie Q : Not-so-simple encoding&decoding example
- Subject: Re : Newbie Q : Not-so-simple encoding&decoding example
- From: email@hidden
- Date: Sat, 27 May 2006 08:41:59 +0200 (CEST)
- Importance: Normal
>Frankly, every single line of this example is a bug.
>
>How about the following instead:
>
>@interface MyDocument : NSDocument
>{
>NSTimer *runTimer; / Objective-C runtime initializes all instance
>variables to nil.
>}
>
>- (void)goForward:(id)dummy /*does one iteration of the loop */
>-(IBAction)toggleRunning:(id)sender;
>
>@end
>
>@implementation MyDocument
>
>-(IBAction)toggleRunning:(id)sender
>{
> if(nil == runTimer)
> {
> NSLog(@"Starting");
> runTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0
> target:self
> selector:@selector(goForward:)
> userInfo:nil
> repeats:YES] retain];
> }
> else
> {
> [runTimer invalidate];
> [runTimer release];
> runTimer = nil;
> }
>}
>
>@end
Thank you for taking the time to answer my question in great detail. My
turn to
correct your code : you forgot the action of the ``stop it all" button. If
I understood
your guidelines correctly, the ``good" code should go like this :
@interface MyDocument : NSDocument
{
NSTimer *runTimer; / Objective-C runtime initializes all instance
variables to nil.
}
- (void)goForward:(id)dummy /*does one iteration of the loop */
-(IBAction)toggleRunning:(id)sender;
-(IBAction) stopItAll : (id) sender;
@end
@implementation MyDocument
-(IBAction) stopItAll : (id) sender
{
NSLog(@"Stopping");
[runTimer invalidate];
}
-(IBAction)toggleRunning:(id)sender
{
if(nil == runTimer)
{
NSLog(@"Starting");
runTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(goForward:)
userInfo:nil
repeats:YES] retain];
}
else
{
[runTimer invalidate];
[runTimer release];
runTimer = nil;
}
}
@end
Ewan
_______________________________________________
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