Re: Bad stardardUserDeafaults
Re: Bad stardardUserDeafaults
- Subject: Re: Bad stardardUserDeafaults
- From: Jens Alfke <email@hidden>
- Date: Thu, 1 Oct 2009 15:14:01 -0700
On Oct 1, 2009, at 2:19 PM, Jacob Schwartz wrote:
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"/
Users/jacobschwartz/Pictures/wallpapers"]];
NSData *pathAsData = [NSKeyedArchiver archivedDataWithRootObject:url];
[defaultValues setObject:pathAsData forKey:JHSPathKey];
[[NSUserDefaults standardUserDefaults]
registerDefaults:defaultValues];
FYI, you don't need to go to the trouble of archiving a URL to put it
in defaults. Just store its absoluteString. That way the defaults are
human-readable if someone ever needs to view/edit them by hand.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *pathAsData = [defaults objectForKey:JHSPathKey];
return [NSKeyedUnarchiver unarchiveObjectWithData:pathAsData];
And then I call:
[textField setStringValue:[[self pathName] absoluteString]]
(pathName is the unarchiving method)
This looks reasonable, although you're not showing us all the code.
And gdb gives me this error:
2009-10-01 17:18:25.391 SyncBackground[452:a0f] -[NSButton
absoluteString]: unrecognized selector sent to instance 0x10013a7b0
What this usually means is that the object you thought you had got
deallocated, and its space was reused for some arbitrary other object.
So the message ends up being sent to that new object instead of the
one you wanted.
What it sounds like is that your code that unarchives the URL is
storing it somewhere without retaining it, and then later on your -
pathName method gets called and returns that pointer, which by now has
been dealloced and points to a different object. But without seeing
how you implemented -pathName, I don't know for sure.
—Jens
_______________________________________________
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