• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re : Newbie Q : Not-so-simple encoding&decoding example
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Newbie Q: Xcode strangeness
  • Next by Date: Re: Determining how the app is run (intel/ppc/rosetta/os version)?
  • Previous by thread: Re: Re : Newbie Q : Not-so-simple encoding&decoding example
  • Next by thread: Drawing a focus ring around an NSScrollView? (drawing glitches)
  • Index(es):
    • Date
    • Thread