Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I check the “Use scalar properties for primitive data types” when generating a new NSManagedObject subclass from my model file?

I created a project using Core Data, and in the .model file I created an entity called Targets.

I added these two entity attributes:

content (String)
targetID (Integer 32)

When I generate the NSManagedObject subclass Xcode asks me:

Use scalar properties for primitive data types?

Should I check this box when generating a new NSManagedObject subclass from my model file?

like image 251
JohnBigs Avatar asked Nov 17 '14 16:11

JohnBigs


People also ask

How to create NSManagedObject subclass in Xcode 10?

From the Xcode menu bar, choose Editor > Create NSManagedObject Subclass. Select your data model, then the appropriate entity, and choose where to save the files. Xcode places both a class and a properties file into your project.

What is scalar type in core data?

Scalar TypesCore 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.


2 Answers

If the box is checked, Xcode will generate scalar types (e.g., int, float, double) for those attributes. If not checked, the attributes will be NSNumbers.

like image 156
0x141E Avatar answered Nov 15 '22 17:11

0x141E


If checking the option, the default value for Number type what you get will be zero, but nil is more reasonable. So, I don't think you should check the box.

like image 45
DawnSong Avatar answered Nov 15 '22 18:11

DawnSong