Re: NSUserDefaults not sticking
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