• 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: NSUserDefaults Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaults Problem


  • Subject: Re: NSUserDefaults Problem
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Fri, 02 Aug 2002 16:22:34 -0400

On 08/02/2002 15:57, "Kyle Mandli" <email@hidden> wrote:

> I am using the NSUserDefaults system to store preferences for my
> application. I set the initial values for the prefs in the +
> (void)initialize function in my main controller. One of the keys stores
> a integer as a NSNumber (through the function setInteger:forKey:) but
> when the program checks to see if that key exists it throws this out to
> the console:
>
> warning: stack pointer (0xbffff5f8) is not aligned to a 16-byte boundary.
> warning: stack pointer (0xbffff5b8) is not aligned to a 16-byte boundary.
> warning: stack pointer (0xbffff1f8) is not aligned to a 16-byte boundary.
> warning: stack pointer (0xbffff5f8) is not aligned to a 16-byte boundary.
> warning: stack pointer (0xbffff5b8) is not aligned to a 16-byte boundary.
> warning: stack pointer (0xbffff1f8) is not aligned to a 16-byte boundary.
>
> and subsequently thinks that the NSNumber is nil and reinitializes the
> value. This only happens with 0. Any other integer will not give this
> output. I know that this is where the pref is being reset and that
> before the application runs the NSNumber is stored properly as a
> NSNumber and as 0 through the PropertyListEditor. Any ideas on what
> could be causing this? Some code is below. Thanks.
>
> + (void)initialize
> {
> NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
>
> if ([defaults integerForKey:@"numViewer"] == nil)
> [defaults setInteger:1 forKey:@"numViewer"];
> }

Using integerForKey:, there is no way to differentiate between a valid
zero value, and a non-existant key. If I understand what you're *really*
trying to do, use this:


+ (void)initialize
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *defaultValue = [NSNumber numberWithInt: 1];
NSDictionary *regDictionary = [NSDictionary
dictionaryWithObjectsAndKeys: defaultValue, @"numViewer", nil];

[defaults registerDefaults:(NSDictionary *)registrationDictionary];
}

--
Clark S. Cox III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSUserDefaults Problem (From: Kyle Mandli <email@hidden>)

  • Prev by Date: NSUserDefaults Problem
  • Next by Date: Re: NSUserDefaults Problem
  • Previous by thread: NSUserDefaults Problem
  • Next by thread: Re: NSUserDefaults Problem
  • Index(es):
    • Date
    • Thread