• 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: How does one use NSTimer?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does one use NSTimer?


  • Subject: Re: How does one use NSTimer?
  • From: Jens Bjerrehuus <email@hidden>
  • Date: Sun, 31 Aug 2003 10:20:06 +0200

sxndag 31. aug 2003 kl. 08:19 skrev djfreezingcold:
The function that shows how much time is left is written, i just need to know how i can get it to be called every 500 milliseconds or so.

Declare your timer like this (you would probably make this an instance variable):

NSTimer *_myTimer;

Then set up your timer like this (e.g. in -awakeFromNib):

_myTimer = [[NSTimer scheduledTimerWithTimeInterval:(0.5)
target:self
selector:@selector(timer:)
userInfo:nil
repeats:YES] retain];

This will call the method -timer: on the target self (the same object where this is set up) every half second. If you want the timer to fire immediately you call [_myTimer fire] to get things going. And, since this is a member variable that I retain here it has to be released in this classes -dealloc method like this:

[_myTimer invalidate];
[_myTimer release];

This first removes the timer from the run-loop and then deallocates it.

The -timer: methods signature looks like this:

- (void)timer:(NSTimer *)aTimer

Kind regards
Jens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >How does one use NSTimer? (From: djfreezingcold <email@hidden>)

  • Prev by Date: Re: Any ~/Sites/ equivalent of NSDocumentDirectory?
  • Next by Date: Re: Any ~/Sites/ equivalent of NSDocumentDirectory?
  • Previous by thread: How does one use NSTimer?
  • Next by thread: Logging entry/exit into methods &/|| functions
  • Index(es):
    • Date
    • Thread