Re: Bindings & Reverting Properties
Re: Bindings & Reverting Properties
- Subject: Re: Bindings & Reverting Properties
- From: Ken Thomases <email@hidden>
- Date: Fri, 21 Aug 2009 23:27:41 -0500
On Aug 21, 2009, at 11:31 AM, Quincey Morris wrote:
On Aug 21, 2009, at 06:27, Dave Keck wrote:
- (void)setHappy: (BOOL)newHappy
{
happy = newHappy;
if (![self save])
self.happy = !happy; // Revert to the old value. Pretend the
recursive call wouldn't
attempt //
another save and cause a stack overflow and crash. It just needs
// to revert the value while
sending
the appropriate KVO notifications.
}
What led you to believe you needed to call the setter recursively?
All you need is:
- (void)setHappy: (BOOL)newHappy
{
happy = newHappy;
if (![self save])
happy = !happy;
}
Except that there's no reason to believe that that the old value of
happy is the opposite of newHappy. It's perfectly possible for
setHappy: to be passed he current value.
- (void)setHappy: (BOOL)newHappy
{
if ((happy && !newHappy) || (!happy && newHappy)) // One way of
safely comparing BOOLs
{
happy = newHappy;
if (![self save])
happy = !happy;
}
}
Regards,
Ken
_______________________________________________
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