Reputation: 881
What are the benefits/downsides between using the NSInteger
(or NSNumber
) and float/int?
What exactly is decimal??
Thank you!
Upvotes: 4
Views: 5320
Reputation: 69469
NSInteger
is just a type def of int
when using it on the iPhone, but on OSX will change form 32 bit int to 64 bit int if you build your code for a 64 bit machine.
NSNumber
is an object that can hold any type of number, being float, integer, double, long ect..
NSDecimal
is a struct which will tell you about some detail about the floating point value of a NSNumber
.
NSDecimalNumber
is a subclass of NSNumber
which can hold a more exact floating point value: see @dreanlax comment
Upvotes: 6
Reputation: 3931
In Core Data, when you specify a property attribute as Integer 16/32/64, then in your code, you will always receive back an NSNumber* instance. The 16/32/64 is just a hint for the underlying store, which is probably going to be SQLite3 for how wide to make the column. If the property in Core Data is going to be used for an enum with 3 or 4 different possible values, you don't need 64bit precision for that column in the database table - so it'll make fetching/storing more efficient, and you don't waste resources.
Selecting 'decimal' as the attribute type will give you an NSDecimalNumber which has methods for performing decimal arithmetic. So, for example, if your property represents money using a decimal is a good option. (Although you will also need to store the currency scale too in that case).
Upvotes: 4
Reputation: 2384
NSInteger and NSDecimal and the like are Foundation Data Types in Objective-C. Be sure to check the reference for more info on them.
Compared with int, an NSInteger will be considered a 32-bit integer when building 32-bit applications, and it is a 64-bit integer for 64-bit applications.
NSNumber on the other hand is a class which can be of any numeric type. Find the reference here. NSNumbers are useful when a simple data type won't do and actual objects are needed to work with such as when inserting numbers into NSArrays.
Upvotes: 0
Reputation: 468
NSInteger is just a typedef of int
NSNumber is a class that contains a number (float/int/...)
Upvotes: 0