Re: Two examples
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