rentzsch / mogenerator

Core Data code generation
http://rentzsch.github.com/mogenerator
MIT License
3.03k stars 395 forks source link

Use scalar properties for primitive data types #379

Open darkwood-studios opened 5 years ago

darkwood-studios commented 5 years ago

Hi there,

the generated classes do have the NSNumber type for bool an double values. In xcode there is a way to check "Use scalar properties for primitive data types" - is there a way to realize this with mogenerator, too?

I want to use model.isCkecked = YES to set the value for a bool.

atomicbird commented 5 years ago

You didn't say what language you're using, but since you use YES rather than true it looks like you mean Objective-C.

With ObjC, your generated code should include a property called isCheckedValue of type BOOL, which you can use as you describe. If you're actually using Swift, this change is coming in the delayed-but-not-forgotten swift42 branch of this project.

darkwood-studios commented 5 years ago

Thank for your fast answer. I'm using objective-c.

It's a huge project with an existing core data with a huge amount of entities and classes.

I want to migrate to generated files from mogenerator - but I don't want to change all lines of codes from (example) isChecked to isCheckedValue - is here a way to use this optionals as I did before?

atomicbird commented 5 years ago

You can get what you describe but only if the isChecked property is configured to use scalar types and is not configured as "optional" in the data model.

screen shot 2018-11-23 at 3 31 39 pm

If the attribute meets both of those requirements, you can then add --template-var scalarsWhenNonOptional=true as one of the arguments when running mogenerator. Then you'll get the following generated property:

@property (atomic) BOOL isChecked;