• 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: NSUserDefaults not sticking
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaults not sticking


  • Subject: Re: NSUserDefaults not sticking
  • From: Graham Cox <email@hidden>
  • Date: Wed, 10 Sep 2014 16:14:15 +1000

On 10 Sep 2014, at 3:43 pm, Rick C. <email@hidden> wrote:

> Thanks for the help.  So I have double-checked and the info in question that is not sticking is NSString/NSData being written:
>
> [[NSUserDefaults standardUserDefaults] setObject:stringObject forKey:@“MyStringKey”];
> [[NSUserDefaults standardUserDefaults] setObject:dataObject forKey:@“MyDataKey”];
>
> Then being read:
>
> NSString *myStringObject = [[NSUserDefaults standardUserDefaults] stringForKey:@“MyStringKey"];
> NSData *myDataObject = [[NSUserDefaults standardUserDefaults] dataForKey:@“MyDataKey”];
>
> I am not manipulating my .plist in any other way only using NSUserDefaults


That should definitely work.

Are you certain something else somewhere isn't using the same key to change the setting? Is it possible that the object passed to -setObject:forKey: isn't a NSString or NSData? The named getter methods also check the type - does it work if you use -objectForKey: instead? Try logging the objects, it's probably something you didn't expect.


> Are you calling synchronise too when you're writing?

That isn't needed. It used to flush the defaults to disk but it no longer does anything AFAIK. It was never needed within a single app session, and was invoked automatically on quit.

--Graham



_______________________________________________

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: NSUserDefaults not sticking
      • From: "Rick C." <email@hidden>
References: 
 >NSUserDefaults not sticking (From: "Rick C." <email@hidden>)
 >Re: NSUserDefaults not sticking (From: Graham Cox <email@hidden>)
 >Re: NSUserDefaults not sticking (From: "Rick C." <email@hidden>)

  • Prev by Date: Re: NSUserDefaults not sticking
  • Next by Date: Re: NSUserDefaults not sticking
  • Previous by thread: Re: NSUserDefaults not sticking
  • Next by thread: Re: NSUserDefaults not sticking
  • Index(es):
    • Date
    • Thread