• 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
Re: Problem with NSUserDefaultsController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with NSUserDefaultsController


  • Subject: Re: Problem with NSUserDefaultsController
  • From: Mark Allan <email@hidden>
  • Date: Tue, 2 Sep 2008 18:04:03 +0100

> For what it's worth, the [sharedUserDefaultsController save:] message is still
 returning before performing the save, so if I send any other messages within
 my savePrefs method, userDefaults will still contain the old value - I'm
 beginning to wonder if this is a bug within NSUserDefaultsController.

As someone else suggested, it appears that the -save method uses a delayed method call to update NSUserDefaults. Binding is a perfectly acceptable way to do this. Alternatively, you can get the value directly from the defaults controller, as it is always immediately changed there:

theValue = [[shared values] valueForKey:@"thevalue"];


You know, I could swear blind that I had already tried that, but I've just done it now and it works! Maybe that's what comes of coding at 1am!


Some other suggestions: storing the shared defaults and controller is really
just a waste of memory. They won't change across invocations.


With the overhead of Objective C messaging, isn't it more efficient to obtain once and store the shared defaults and controller for later use? Admittedly, we're probably splitting hairs here with a very small number of messages vs very small memory requirement, but I was always taught that space is cheaper than time. If necessary, space can be reclaimed whereas (cpu) time can't.


It would also be a good idea to keep your types consistent: a slider expects to manipulate a numeric value, and as you see it stores its value as a number in the prefs. Your object property should also be an NSNumber, not an NSString.

Yes, that was just laziness on my part as I played around with this. This particular app will never actually do anything, I was simply trying to see how it will work when I start writing the preferences routines for my real application. The types will definitely match when I do it for that one! :)


M

_______________________________________________

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: Problem with NSUserDefaultsController
      • From: Keary Suska <email@hidden>
References: 
 >Re: Problem with NSUserDefaultsController (From: Keary Suska <email@hidden>)

  • Prev by Date: Re: converting from decimal to hexadecimal
  • Next by Date: Re: Path animation with CGPathAddArcToPoint
  • Previous by thread: Re: Problem with NSUserDefaultsController
  • Next by thread: Re: Problem with NSUserDefaultsController
  • Index(es):
    • Date
    • Thread