• 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
Bindings & Reverting Properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings & Reverting Properties


  • Subject: Bindings & Reverting Properties
  • From: Dave Keck <email@hidden>
  • Date: Fri, 21 Aug 2009 03:27:12 -1000

Hey list,

I've implemented a custom bindings-compatible preferences controller object
- let's call it MyPrefsController. It's similar to NSUserDefaultsController,
but has lots of different functionality, and inherits directly from
NSObject.

As the user is changing the preferences in the UI, the preferences file
on-disk is kept in sync. But due to the nature of the app, sometimes saving
the preferences will fail. If this is the case, the UI control should simply
revert back to its previous value before the attempted save. It's this
revert that's giving me trouble.

Here's a vastly over-simplified setter method that displays my problem.
Suppose a checkbox in the UI is bound to the 'happy' property, which has the
following setter:

- (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.
}

If saving fails, the 'happy' property gets reverted. But this doesn't get
reflected for the checkbox in the UI - it still shows the new value as if no
error occurred. One way around this is to schedule 'self.happy = !happy' to
be executed in the next iteration of the run loop. But that's kludgy.

The KVC validation methods seem like a possibility, but they're for
validating the value before it's applied to the model, rather than reverting
the value of the property after-the-fact.

Is there a right way to do this?

Thanks!

David
_______________________________________________

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

  • Follow-Ups:
    • Re: Bindings & Reverting Properties
      • From: Quincey Morris <email@hidden>
    • Re: Bindings & Reverting Properties
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: iPhone: Accessing variable from another view controller
  • Next by Date: Re: iPhone: Accessing variable from another view controller
  • Previous by thread: Re: iPhone: Accessing variable from another view controller
  • Next by thread: Re: Bindings & Reverting Properties
  • Index(es):
    • Date
    • Thread