问题描述
默认情况下,从数据模型创建NSManagedObject子类文件时,Core Data为字符串类型列创建类型为NSString(非原子,保留)的属性。我可能会完成由于性能考虑,但是,我实现Data Mapper模式,其中核心数据NSManagedObject子类与模型类分离。所以当将模型类转换为Core数据NSManagedObject子类时,retain只是分配一个指针而不是一个副本。从架构的角度来看,它会在核心数据访问和模型类之间进行逻辑分离,因此我需要使用copy而不是retain。
By default when creating NSManagedObject subclass file from data model, Core Data creates properties of type NSString (nonatomic, retain) for string type columns. I might be done due to performance consideration, however, I'm implementing Data Mapper pattern where core data NSManagedObject subclasses are separated from model classes. So when converting model classes to Core data NSManagedObject subclass, retain just assigns a pointer and not a copy. From the architecture point of view, it brakes logic separation between core data access and model classes, so I need to use copy instead of retain.
这是唯一的方法是手动更改NSManagedObject子类中的属性?
Is it the only way to do is manually to change properties in NSManagedObject subclasses?
推荐答案
唯一的方法是更改NSManagedObject子类中的属性的声明。值得庆幸的是,Core Data会自动处理余下的。
The only way to do this is to change the declaration of the property in an NSManagedObject subclass. Thankfully, Core Data then handles the rest automatically.
这篇关于如何使NSManagedObject NSString属性与“复制”而不是“保留”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!