0

I'm using Mogenerator to generate my models. So in my Human model I have

- (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;
}

Since the Machine class has all the properties I haven't readded them into the Human file. However I get an error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppointmentGrid setEmployeeId:]: unrecognized selector sent to instance

Do I really need to redefine everything in my Human file?

Bot
  • 11,868
  • 11
  • 75
  • 131

1 Answers1

1

Instances of NSManagedObject must be created using the designated initialiser

initWithEntity:insertIntoManagedObjectContext:

The Core Data property accessor methods are created dynamically at runtime, and that cannot work if the object was created with a plain init method.

This might work (untested):

AppointmentGrid *appointmentGridCopy = [[[self class] allocWithZone:zone] 
    initWithEntity:self.entity
    insertIntoManagedObjectContext:self.managedObjectContext];
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • ahh yes... completely spaced on that part! ty – Bot Feb 05 '14 at 19:25
  • as a side note you need to create in the same context or you cannot copy relationships without manual work. – Bot Feb 05 '14 at 19:26
  • @Bot: You are welcome. (Note that this is a runtime exception and is therefore unrelated to mogenerator, which only creates the source code.) – Martin R Feb 05 '14 at 19:27