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

Objective CCore Data

Objective C Problem Overview


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

Objective C Solutions


Solution 1 - Objective C

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

Solution 2 - Objective C

> 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrowwingmanView Question on Stackoverflow
Solution 1 - Objective CEvgeny ShurakovView Answer on Stackoverflow
Solution 2 - Objective CPerryView Answer on Stackoverflow