• 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: Mysterious NULL Coming From NSUserDefaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mysterious NULL Coming From NSUserDefaults


  • Subject: Re: Mysterious NULL Coming From NSUserDefaults
  • From: "Alex Wait" <email@hidden>
  • Date: Sun, 6 Jul 2008 22:40:05 -0700

Indeed. Both the setters and getters are being called. I looked in the plist
file for my app and I see "BgColor" and "LineColor"
as values with a bunch of digits/hex for its value.

On Sun, Jul 6, 2008 at 10:13 PM, Thomas Mueller <
email@hidden> wrote:

> Hi,
>
> Are the setters actually being called? Maybe the values are never
> being stored in the defaults? Maybe have a look at the preferences
> file for your app (in ~Library/Preferences) to see if anything is
> stored in there. I guess you won't be able to see *which* color is
> stored, though.
>
> Just an idea; I'm just a few chapters ahead of you, so I'm probably
> wrong... :-)
>
> Regards,
> Thomas
>
>
> 2008/7/7 Alex Wait <email@hidden>:
> > I've been enjoying NSUserDefaults when going through the Hillegeass book.
> >
> > I've decided to do a small app that has two colors it stores. I get these
> > colors from a colorwell via  Preference Pane.
> >
> > I have bounded the values of the wells to backGroundWell and lineWell in
> IB.
> >
> > I have the appropriately named methods. I know my bindings are ok becuase
> if
> > I just return [NSColor whiteColor] instead of the data
> > from NSUserDefaults, they're yellow when I open the pane. so that's ok.
> >
> > I am pretty sure I'm getting a null from the defaults because the wells
> are
> > black. I have no "blackColor" in my project. Already searched for that.
> ;)
> >
> > What am I doing wrong? I thought that NSUserDefaults was pretty simple...
> >
> > Below are my getters and setters.
> >
> > -(NSColor*)backGroundWell
> > {
> >
> >    NSLog(@"called BGwell");
> >
> >    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
> >    NSData* data = [defaults objectForKey:@"BGCOLOR"];
> >    NSColor* newColor = [NSKeyedUnarchiver unarchiveObjectWithData:data];
> >    NSLog(@"retrieved Color for BG is %@", newColor);
> >    //NSLog(@"%@",[NSKeyedUnarchiver unarchiveObjectWithData:data]);
> >    return [NSKeyedUnarchiver unarchiveObjectWithData:data];
> > }
> > -(NSColor*)lineWell
> > {
> >
> >    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
> >    NSData* data = [defaults objectForKey:@"LINECOLOR"];
> >    return [NSKeyedUnarchiver unarchiveObjectWithData:data];
> > }
> >
> > -(void)setBackGroundWell: (NSColor*)newColor
> > {
> >    NSLog(@"New Color is %@", newColor);
> >    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
> >    NSColor* color = [backGroundWell color];
> >    NSData* colorData = [NSKeyedArchiver
> archivedDataWithRootObject:color];
> >    [defaults setObject:colorData forKey:@"BGCOLOR"];
> >    NSLog(@"changing background color");
> > }
> > -(void)setLineWell: (NSColor*)newColor
> > {
> >    NSLog(@"New Color is %@", newColor);
> >    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
> >    NSData* colorData = [NSKeyedArchiver
> > archivedDataWithRootObject:[lineWell color] ];
> >    [defaults setObject:colorData forKey:@"LINECOLOR"];
> >    NSLog(@"changing line color");
> >
> > }
> >
> >
> > -------
> > Below is my +(void) initialize method
> >
> > +(void) initialize
> > {
> >
> >    NSMutableDictionary* defaultValues = [NSMutableDictionary dictionary];
> >
> >    NSData* backgroundColorData = [NSKeyedArchiver
> > archivedDataWithRootObject:[NSColor greenColor] ];
> >    NSData* lineColorData = [NSKeyedArchiver
> > archivedDataWithRootObject:[NSColor whiteColor] ];
> >
> >    [defaultValues setObject:backgroundColorData forKey:@"BGCOLOR"];
> >    [defaultValues setObject:lineColorData forKey:@"LINECOLOR"];
> >
> >    [[NSUserDefaults standardUserDefaults]
> registerDefaults:defaultValues];
> >    NSLog(@"registered defaults %@", defaultValues);
> >
> > }
> >
> >
> > --
> > If you can't be kind, at least have the decency to be vague.
> > _______________________________________________
> >
> > 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
> >
>



--
If you can't be kind, at least have the decency to be vague.
_______________________________________________

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: Mysterious NULL Coming From NSUserDefaults
      • From: "Alex Wait" <email@hidden>
References: 
 >Mysterious NULL Coming From NSUserDefaults (From: "Alex Wait" <email@hidden>)

  • Prev by Date: Re: Reading/Writing application dictionary files.
  • Next by Date: Re: Mysterious NULL Coming From NSUserDefaults
  • Previous by thread: Mysterious NULL Coming From NSUserDefaults
  • Next by thread: Re: Mysterious NULL Coming From NSUserDefaults
  • Index(es):
    • Date
    • Thread