NSmanagedObject copyWithZone issues

五迷三道 提交于 2019-12-20 03:24:11

问题


I have a custom class Thing:NSManagedObject with an attribute of adminName.

I am trying to create a copyWithZone function in this Thing class, but when I run the app it says setAdminName doesn't exist.

In my implementation file I am using

@dynamic adminName;


-(id) copyWithZone: (NSZone *) zone
{
Thing *regCopy = [[Thing allocWithZone: zone] init];
regCopy.attendeeNum = [self adminName];

return regCopy;
}

I don't believe I can just change @dynamic to @synthesize since I am using Core Data.


回答1:


NSManagedObject does not conform to the NSCopying protocol. If you want to create a new record with the same data, just insert a new object and assign the values from the first object to the second object.




回答2:


You will need to create a new Thing the same way you created the original Thing something like

Thing *regCopy = [NSEntityDescription insertNewObjectForEntityForName:@"Thing" inManagedObjectContext:self.managedObjectContext]



来源:https://stackoverflow.com/questions/11974701/nsmanagedobject-copywithzone-issues

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