• 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: NSTimers starting, stopping, pausing...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimers starting, stopping, pausing...


  • Subject: Re: NSTimers starting, stopping, pausing...
  • From: Chris Kane <email@hidden>
  • Date: Sun, 12 May 2002 11:08:29 -0700

On Saturday, May 11, 2002, at 12:41 AM, David Newberry wrote:
The game basically needs to do three things: Start, Stop and Pause. To start, I call scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:. I'm most unsure about this call... should I not call it after the timer has previously been created and invalidated?

To stop the timer, I send the invalidate message.

To pause or unpause the timer, I set a global BOOL variable to either YES or NO, and check its value in the method which is called by the timer.

At no point (except in the initializing method) do I ever set my timer variable to nil. However, I am getting a EXC_BAD_ACCESS messages. This is confusing to me. Is it because of the invalidate message? Possible to tell from the info I've given?

On stop or pause, what I would do is -invalidate the timer, and throw it away (set your variable to nil). On start or resume, create a new timer. For best form, if you're going to keep a pointer to the timer in your own variable, you should keep a retain on the timer as well (retain the return value of scheduledTimer... when you assign it to your variable), and release it just before nil'ing out the variable.

Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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: 
 >NSTimers starting, stopping, pausing... (From: David Newberry <email@hidden>)

  • Prev by Date: NSTableView and Java
  • Next by Date: Re: NSTimer Problem
  • Previous by thread: NSTimers starting, stopping, pausing...
  • Next by thread: Bundle identifiers
  • Index(es):
    • Date
    • Thread