Re: Logical and - second operator evaluated?
Re: Logical and - second operator evaluated?
- Subject: Re: Logical and - second operator evaluated?
- From: Shawn Erickson <email@hidden>
- Date: Sun, 1 Mar 2009 13:10:49 -0800
On Sun, Mar 1, 2009 at 12:59 PM, Martijn van Exel <email@hidden> wrote:
> I'm glad the && operator does what I'd expect it to do and will not evaluate
> the second expression if the first one evaluates false.
> So there's something else going on here. The whole NSTimer concept is also
> new to me so I must have done something strange there.
>
> What I do is:
> * Two NSTimer instances are created upon the user pressing a button. One is
> a non-repeating NSTimer for executing a delayed action. The other is a
> repeating one updating the title of a UIActionSheet (iPhone) so it shows a
> count down.
Consdier using -[NSObject performSelector:withObject:afterDelay:] for
the delayed operation.
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/performSelector:withObject:afterDelay:
> * The method invoked by the first timer also dismisses the UIActionSheet.
> * In the didDismissWithButtonIndex callback, the two timers would be
> invalidated. This would cause a BAD_ACCESS crash.
>
> I think I figured out what goes wrong: In the time it takes to dismiss the
> UIActionSheet (animated), the repeating timer, still valid, would call its
> designated method to update the UIActionSheet title. This method creates an
> NSTimeInterval calculated from
> [[timer fireDate] timeIntervalSinceDate:[NSDate date]];
> and this probably would cause the crash, [timer fireDate] returning because
> it already expired.
If you are getting a crash you should have a crash log (or trap it in
the debugger). This would give you the location of your crash.
Likely the timer is getting deallocated out from under your code. If
you create a timer using a convenience method it isn't owned by you
but it will continue to exist as long as it scheduled. When you
invalidate it, assuming you didn't retain it someplace in your code
(aka take ownership), then likely you are removing the last retain on
the timer so it gets deallocated. To avoid problems like this it often
is best to store a reference to the timer in a retaining property
and/or structure the code so this type of thing isn't a problem.
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden