xcode 7 generates core data entity with additional CoreDataProperties category

后端 未结 3 1595
误落风尘
误落风尘 2021-01-31 15:45

I have strange new feature in xcode 7, when I generate new NSManagedObject subclass then xcode create two classes: entity and their CoreDataProperties category, which contain fu

3条回答
  •  情歌与酒
    2021-01-31 16:24

    Previously the generated code went into a EntityName.h and EntityName.m that you had to "extend" with an interface such as EntityName+Create.h and EntityName+Create.m.

    This was hard to understand for beginners who often modified the EntityName.m class and lost their code.

    Now it is in the right way: the code generator will not erase the existing code.

    The other answers are very good at explaining the new system.

    But nobody talks about the new compatibility issue if you have entities based on the old system.

    My solution: I still put my own code in EntityName+Create.m, but in EntityName+Create.h I refer to EntityName+CoreDataProperties.h instead of just EntityName.h (I emptied the previously generated code in EntityName.h and EntityName.m). This solution avoided me to move my code from EntityName+Create.m and to change all references to EntityName+Create.h.

    I hope this helped you.

提交回复
热议问题