user6631314
user6631314

Reputation: 1958

iOS/Objective-C: Store Decimal as NSNumber in CoreData

I have an attribute in CoreData used for sorting that is an NSNumber. Currently, all of the values in it are NSNumbers represting integers, ie 1,2,3,4 etc.

However, I now have a reason to add some NSManagedObjects with intermediate values. Is it possible to store a decimal in an attribute in CoreData with a data type of NSNumber?

For example, I might have one managed object with a sort order of 1 and another with a sort order of 2. I'd like to move one in between and give it a sort order of 1.5.

Is this allowed?

Thanks in advance for any suggestions.

Upvotes: 0

Views: 403

Answers (1)

vadian
vadian

Reputation: 285079

Basically Core Data supports many different types represented by NSNumber

  • integer16 (short int)
  • integer32 (int)
  • integer64 (long)
  • double
  • float
  • boolean

decimal is represented by NSDecimalNumber

You have to choose the appropriate attribute type in the Core Data model

Upvotes: 2

Related Questions