• 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: Two examples
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Two examples


  • Subject: Re: Two examples
  • From: Brian Webster <email@hidden>
  • Date: Mon, 28 Jan 2002 12:44:06 -0600

On Monday, January 28, 2002, at 11:35 AM, cocoa-dev-
email@hidden 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.)

-(void)startTheTimer
{
theTimer = [[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerFired:) repeats:YES] retain];
}

-(void)timerFired:(NSTimer*)timer
{
[self updateImage];
}

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

-(void)quitDock
{
AppleEvent quitEvent;
AEDesc addressDesc;
OSErr err;
OSType dockSig = 'dock';

err = AECreateAEDesc(typeApplSignature, &dockSig, sizeof(OSType), &addressDesc);
err = AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, &addressDesc, kAutoGenerateReturnID, kAnyTransactionID, &quitEvent);
err = AESend(&quitEvent, NULL, kAENoReply, kAENormalPriority, kAEDefaultTimeout;, NULL, NULL);
AEDisposeDesc(quitEvent);
AEDisposeDesc(addressDesc);
}

All code typed into Mail, untested.

--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster


  • Prev by Date: Showing progress in a sheet
  • Next by Date: Re: NSCalendarDate and locale
  • Previous by thread: Re: Showing progress in a sheet
  • Next by thread: Springs and struts with splitview
  • Index(es):
    • Date
    • Thread