Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MorphingDragon

macrumors 603
Original poster
Mar 27, 2009
5,159
6
The World Inbetween
What are the advantages of using NSNumber etc? (Apart from treating them like objects) Like memory management or performance benefits? Because its a lot of code when I simply would require a local variable; int, float, char etc.
 
What are the advantages of using NSNumber etc? (Apart from treating them like objects) Like memory management or performance benefits? Because its a lot of code when I simply would require a local variable; int, float, char etc.

The main purpose is that they're objects so they can be used in places where primitive types can't be used such as in NSArrays, etc.
 
Store them as primitives in your app when you can since NSNumber is immutable, and only use NSNumber when necessary (storing in an NSDictionary, NSUserDefaults, or any other API that requires an object, etc).
 
Obviously storing them in NSArrays and NSDictionaries, but also a much easier way to write them into a file since NSArray and NSDictionary can be serialized into a plist file as can NSNumber and NSString etcetera.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.