我正在使用Mogenerator来生成我的模型。所以在我的人体模型中我有
- (id)copyWithZone:(NSZone *)zone
{
AppointmentGrid *appointmentGridCopy = [[[self class] allocWithZone:zone] init];
[appointmentGridCopy setEmployeeId:self.employeeId];
[appointmentGridCopy setEmployeeObject:self.employeeObject];
[appointmentGridCopy setServiceId:self.serviceId];
[appointmentGridCopy setServiceObject:self.serviceObject];
[appointmentGridCopy setStartTimestamp:self.startTimestamp];
[appointmentGridCopy setEndTimestamp:self.endTimestamp];
[appointmentGridCopy setAppointmentGridSlots:self.appointmentGridSlots];
return appointmentGridCopy;
}
由于Machine类具有所有属性,因此我没有将它们读入Human文件中。但是我收到了错误
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppointmentGrid setEmployeeId:]: unrecognized selector sent to instance
我真的需要重新定义Human文件中的所有内容吗?
答案 0 :(得分:1)
NSManagedObject
的实例必须使用指定的初始化
initWithEntity:insertIntoManagedObjectContext:
Core Data属性访问器方法是在运行时动态创建的
如果使用普通init
方法创建对象,则无法工作。
这可能有用(未经测试):
AppointmentGrid *appointmentGridCopy = [[[self class] allocWithZone:zone]
initWithEntity:self.entity
insertIntoManagedObjectContext:self.managedObjectContext];