• 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: Newb Question re NSUserDefaults and Ints
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newb Question re NSUserDefaults and Ints


  • Subject: Re: Newb Question re NSUserDefaults and Ints
  • From: Graham Cox <email@hidden>
  • Date: Sat, 30 Aug 2008 14:04:40 +1000


On 30 Aug 2008, at 11:54 am, Brad Gibbs wrote:

NSLog(@"gradient angle is %d", [elementBarGradientAngleTextField intValue]);
[defaults setInteger:[elementBarGradientAngleTextField intValue] forKey:ICNElementBarGradientAngleKey];
NSLog(@"Element bar angle is now: %d", [ICNElementBarGradientAngleKey intValue]);
}


I get:

2008-08-29 18:42:10.627 Icon[35645:10b] gradient angle is 75
2008-08-29 18:42:10.628 Icon[35645:10b] Element bar angle is now: 0

Hmm, yes. Well, what is your code doing? It's first taking the intValue from elementBarGradientAngleTextField. It then sets that value in the user defaults, quite correctly, using the key "ICNElementBarGradientAngleKey" which I take it is defined somewhere as a constant literal string. You then ask the KEY for its intValue. The key's intValue is indeed 0, because the key is "ICNElementBarGradientAngleKey" which isn't a number.


I think you mean:

NSLog(@"Element bar angle is now: %d", [defaults integerForKey:ICNElementBarGradientAngleKey]);

which should return the same as the first log.


meant to be used with an int, or an object, such as NSUInteger? What am I doing wrong?


NSInteger is NOT an object. It's just another name for int. Just because something is prefixed by 'NS' do not assume its an object - there are many, many things in Cocoa that are prefixed 'NS' that are not objects - types, constants, functions, you name it. You can really tell what is or isn't an object purely from its name alone - check the documentation.

hth,

Graham

_______________________________________________

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: Newb Question re NSUserDefaults and Ints
      • From: Graham Cox <email@hidden>
References: 
 >Newb Question re NSUserDefaults and Ints (From: Brad Gibbs <email@hidden>)

  • Prev by Date: Re: Newb Question re NSUserDefaults and Ints
  • Next by Date: Re: Newb Question re NSUserDefaults and Ints
  • Previous by thread: Re: Newb Question re NSUserDefaults and Ints
  • Next by thread: Re: Newb Question re NSUserDefaults and Ints
  • Index(es):
    • Date
    • Thread