Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data "use scalar properties for primitive data types" check box

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)?

like image 994
rowwingman Avatar asked Dec 11 '12 11:12

rowwingman


2 Answers

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).

like image 144
Evgeny Shurakov Avatar answered Sep 19 '22 16:09

Evgeny Shurakov


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 endless floatValue, boolValue, integerValue, or similar calls on these NSNumber 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, or BOOL, and it will work with Core Data. Xcode even has a little checkbox in the save dialogue of the NSManagedObject generator (“Use scalar properties for primitive data types”) which does this for you.

Source: objc.io - Data Models and Model Objects

like image 39
Perry Avatar answered Sep 20 '22 16:09

Perry