Swift + CoreData: Cannot Automatically Set Optional Attribute On Generated NSManagedObject Subclass

前端 未结 2 1875
面向向阳花
面向向阳花 2020-12-02 13:27

I have a coredata entity named Record and has a property dateUpdated. I noticed that the generated NSManagedObject subclass has no optional mark (?)

CoreData

2条回答
  •  遥遥无期
    2020-12-02 13:42

    Workaround:

    Yes this seems like a bug / limitation. Use non-scalar types to workaround this problem.

    Optional attributes

    • Check the optional check box
    • Uncheck scalar check box

    Non-Optional attributes

    • Uncheck the optional check box
    • Check scalar check box

    Probable reason:

    The Swift code gets translated into Objective-C and Objective-C doesn't support nil values for non-class types.

提交回复
热议问题