Two questions about Objective-C

  • Posted: 28 January 2002 05:51 PM

    Hey, could anyone give me example code blocks that:

    1. Demonstrate how to create an NSTimer that calls a method:
    (void)updateImage
    every 5 seconds. (Assume that the class that this code is in has a timer variable called “theTimer” declared in the header file.)

    2. Create and send an AppleEvent: class “aevt”, event ID “quit”, to the Dock.

    Thanks.

         
  • Posted: 28 January 2002 05:51 PM #1

    On 2002-01-27 16:19, spazum64 wrote:
    Hey, could anyone give me example code blocks that:

    1. Demonstrate how to create an NSTimer that calls a method:
    (void)updateImage
    every 5 seconds. (Assume that the class that this code is in has a timer variable called “theTimer” declared in the header file.)

    2. Create and send an AppleEvent: class “aevt”, event ID “quit”, to the Dock.

    Thanks.

    Well, I haven’t done any AppleScript code in ages, but I can post some code demonstrating timers.

    This comes from a simple program I wrote to display time in native UNIX format (seconds since epoch) for the billion-second rollover last year. This is the initialization code for the TimeController object:

    -(id)init {
        clockIsRunning 
    YES;
        
    theTimer [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateSecs:) userInfo:NULL repeats:YES];
        return 
    self;

    The code sets a global flag to say the clock is on, and then instantiates a timer object to fire every second (withTimeInterval), sending a message to the Timecontroller object (target:self) asking to update the seconds count (selector:@selector etc…). The userInfo I can’t remember the purpose of userInfo, and repeats:YES ensures that the timer fires every second.

    Hopefully, you can adapt that to meet your needs.

    Jason

    Signature

    Honorary Handsome Brute of TMO
    Bearded UNIX Guru-in-Training

    Call me jvarner; it’s shorter and doesn’t require capitalization.