Bad stardardUserDeafaults
Hello all, So I have a code segment that turns an NSString that is a file path on my computer into an NSURL, archives the NSURL into NSData, and then puts that into a NSMutableDictionary to be saved in the standardUserDefaults. I can archive and unarchive the NSData with no problem, but if I try to unarchive it after taking out of the dictionary, then it tells me (at least I think that is what gdb is telling me) that it is an NSButton. I have no clue where this could have come from and was hoping someone has had this problem before and fixed it. Thanks -Jake Schwartz ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
You need to post your archiving and unarchiving code. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
On Oct 1, 2009, at 3:32 PM, Jacob Schwartz wrote: So I have a code segment that turns an NSString that is a file path on my computer into an NSURL, archives the NSURL into NSData, and then puts that into a NSMutableDictionary to be saved in the standardUserDefaults. I can archive and unarchive the NSData with no problem, but if I try to unarchive it after taking out of the dictionary, then it tells me (at least I think that is what gdb is telling me) that it is an NSButton. I have no clue where this could have come from and was hoping someone has had this problem before and fixed it. There's no way we can possibly answer your question without seeing your code. It *could* be a memory management issue or it could be a mistaken assignment, but there's no way to tell why your code is misbehaving when you haven't actually shown it. Just post the relevant parts (the storage part and the retrieval part). You don't have to share your whole project, but you *do* have to post the relevant code if you want help debugging it. -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
Alright I'll have to do it after I get out of class. I didn't post it right away in case this was a common mistake, simple use of a wrong method. Thanks -Jake On Oct 1, 2009, at 3:38 PM, I. Savant idiotsavant2...@gmail.com wrote: On Oct 1, 2009, at 3:32 PM, Jacob Schwartz wrote: So I have a code segment that turns an NSString that is a file path on my computer into an NSURL, archives the NSURL into NSData, and then puts that into a NSMutableDictionary to be saved in the standardUserDefaults. I can archive and unarchive the NSData with no problem, but if I try to unarchive it after taking out of the dictionary, then it tells me (at least I think that is what gdb is telling me) that it is an NSButton. I have no clue where this could have come from and was hoping someone has had this problem before and fixed it. There's no way we can possibly answer your question without seeing your code. It *could* be a memory management issue or it could be a mistaken assignment, but there's no way to tell why your code is misbehaving when you haven't actually shown it. Just post the relevant parts (the storage part and the retrieval part). You don't have to share your whole project, but you *do* have to post the relevant code if you want help debugging it. -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
On Oct 1, 2009, at 3:49 PM, Jacob Schwartz wrote: I didn't post it right away in case this was a common mistake That's the problem. If you think about it, how can we know what kind of mistake it was without seeing what you actually did? :-) -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
I meant like if it was a common case. Nevermind though, here is the code: Archiving: 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]; Unarchiving: 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) And gdb gives me this error: 2009-10-01 17:18:25.391 SyncBackground[452:a0f] -[NSButton absoluteString]: unrecognized selector sent to instance 0x10013a7b0 Thank you again. -Jake On Oct 1, 2009, at 3:51 PM, I. Savant wrote: On Oct 1, 2009, at 3:49 PM, Jacob Schwartz wrote: I didn't post it right away in case this was a common mistake That's the problem. If you think about it, how can we know what kind of mistake it was without seeing what you actually did? :-) -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Bad stardardUserDeafaults
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com