On Sun, Mar 1, 2009 at 21:34, Clark Cox <clarkc...@gmail.com> wrote:

> On Sun, Mar 1, 2009 at 12:06 PM, Martijn van Exel <mve...@gmail.com>
> wrote:
> > Hi devs,
> >
> > I can't seem to get away with
> >                if(timer!=nil && [timer isValid]) [timer invalidate];
> > if the timer object does not exist.
> > I'm not used to the second operator of the && even being evaluated if the
> > first one evaluates false (Java, .NET). This is not the case in (Obj)C?
>
> No, just as in C (and C++, when operator overloading isn't involved),
> the second operand to the && operator is never evaluated if the first
> evaluates to zero. What, exactly, is going wrong?
>

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.
* 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.

Thanks for your insights,

Martijn
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to