NSmanagedObject copyWithZone issues

2.4k Views Asked by At

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.

2

There are 2 best solutions below

1
On BEST ANSWER

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
On

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]