0

我正在使用 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 文件中的所有内容吗?

4

1 回答 1

1

的实例NSManagedObject 必须使用指定的初始化程序创建

initWithEntity:insertIntoManagedObjectContext:

Core Data 属性访问器方法是在运行时动态创建的,如果对象是使用普通方法创建的,则无法正常工作init

这可能有效(未经测试):

AppointmentGrid *appointmentGridCopy = [[[self class] allocWithZone:zone] 
    initWithEntity:self.entity
    insertIntoManagedObjectContext:self.managedObjectContext];
于 2014-02-05T17:38:49.980 回答