When should I check "use scalar properties for primitive data types" during creating NSManagedObject
objects?
What it will cost me (will my data base improve performance or be more lightweight)?
Before iOS 5 and OSX 10.7 scalar properties can't be auto-generated and you had to add setter and getter implementations, which cause some penalty. Auto-generated properties are optimized. I'm not aware of any other penalties.
Scalar and non-scalar properties are represented by the same types in DB, so there will be no change in DB's size.
You should choose when to use scalar depending on the way you're going to access these properties. For example, you will need to wrap scalar properties in cocoa object if you're going to add them to collection (NSArray, NSSet, NSDictionary).
Core Data has support for many common data types like integers, floats, booleans, and so on. However, by default, the data model editor generates these attributes as
NSNumber
properties in the managed object subclasses. This often results in endlessfloatValue
,boolValue
,integerValue
, or similar calls on theseNSNumber
objects in the application code.But we can also just specify those properties with their correct scalar type, e.g. as
int64_t
,float_t
, orBOOL
, and it will work with Core Data. Xcode even has a little checkbox in the save dialogue of theNSManagedObject
generator (“Use scalar properties for primitive data types”) which does this for you.
Source: objc.io - Data Models and Model Objects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With