Re: Bindings & Reverting Properties
Re: Bindings & Reverting Properties
- Subject: Re: Bindings & Reverting Properties
- From: Dave Keck <email@hidden>
- Date: Sun, 23 Aug 2009 15:54:54 -1000
For the archives...
The cleanest way I've found to get around my problem is best illustrated
with some example code:
=========================
- (void)setHappy: (BOOL)newHappy
{
BOOL oldHappy = happy;
happy = newHappy;
if (![self save])
{ // Do the revert now
happy = oldHappy;
// Update the UI later
[self performSelector: @selector(updateUI)
withObject: nil
afterDelay: 0.0];
}
}
- (void)updateUI
{
[self willChangeValueForKey: @"happy"];
[self didChangeValueForKey: @"happy"];
}
=========================
In the above example, I do the actual revert in the current iteration of the
run loop, and save the updating of the UI for the next iteration. I also
thought about scheduling the entire revert task for the next iteration, but
found this wasn't as good an option. The reason it's not as good is because
before the revert happens, the preferences will temporarily reflect a state
that hasn't (and won't) be saved to disk. So if someone asks for the value
of happy during the _current_ iteration of the run loop, it will erroneously
return the temporary value before the revert happens. Therefore, it's a
better idea to simply do the revert now, and update the UI later.
Perhaps someone, somewhere will find that information useful.
_______________________________________________
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