Jack Humphries
Jack Humphries

Reputation: 13267

Advantage to using NSNumbers over integers or floats?

What is the advantage of using NSNumbers over integers or floats? Why do they exist and why are they used? It's much easier to get integers and floats out of UI objects (intValue & floatValue), whereas you have to use the NSNumberFormatter to do the same for NSNumbers. What do you use NSNumbers for?

Upvotes: 2

Views: 230

Answers (1)

Vladimir
Vladimir

Reputation: 170839

NSNumber objects primarily used to store numbers in objective-c containers (e.g. NSArray, NSDictionary etc) - as they require objects as elements and cannot store plain types.

Also CoreData properties (prior to iOS5) cannot be plain types - so you need to use NSNumbers here as well.

In other scenarios it may be indeed more convenient and efficient to use plain types.

Upvotes: 6

Related Questions