Re: Bad stardardUserDeafaults
Re: Bad stardardUserDeafaults
- Subject: Re: Bad stardardUserDeafaults
- From: Jacob Schwartz <email@hidden>
- Date: Thu, 1 Oct 2009 19:08:44 -0400
I right, I didn't hit reply all.
So I did found out how to do the breakpoint thing and I came across
this:
defaults = (NSUserDefaults *) 0x100425070
pathAsData = (NSData *) 0x0
I've done enough programming to that a memory address of 0x0 is null.
This was in the first line of the pathName method, which I'll take to
mean I am not doing a good job either saving the registering the
dictionary as the standardUserDefaults or saving the object into the
dictionary. But I haven't done enough Objective C programming to know
what I did wrong/poorly.
Thanks again for all the help
-Jake
On Oct 1, 2009, at 6:14 PM, Jens Alfke wrote:
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