NSManagedObject subclass property in category

怎甘沉沦 提交于 2019-11-28 02:22:01

In previous Xcode releases, only a class was created for each Core Data entity, e.g. the class "BibleAudio" in BibleAudio.h/.m. These files were overwritten each time you re-created the managed object subclasses. Therefore, to add your own functionality to the Core Data class, you had to define a category (in separate files) on the class.

The great disadvantage was that you can add methods in class categories, but not instance variables. So you could not add a simple property (backed up by an instance variable). One possible workaround was to define a transient property in the entity, but this had also disadvantages.

Now Xcode creates a class "BibleAudio" (in BibleAudio.h/.m) which is essentially empty, and a category "BibleAudio (CoreDataProperties)" in BibleAudio + CoreDataProperties.h/.m The category files contain all the Core Data properties, and are overwritten when you re-create the managed object subclasses.

The class files BibleAudio.h/.m are created only once and never overwritten. You can add functionality there: methods as before, but also custom properties and instance variables. Because it is a class and not a category, the old restrictions don't apply anymore.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!