In my app I want to use the the ManagedObjectContext created by the AppDelegate in another class (myClass). For this I first created an Instance Variable in MyClass to store the objectContext:
NSManagedObjectContext *managedObjectContext;
I also defined getter and setter with @property.
To set the instance variable I assigned it the managedObject Context of AppDelegate after initializing it:
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
myClass *myClassInstance = [[myClass alloc]init];
[myClassInstance setManagedObjectContext:[self managedObjectContext]];
}
Now, when I’m running the App I get the following:
-[NSManagedObjectContext copyWithZone:]: unrecognized selector sent to instance 0x100634c90
To be honest I don’t really know what to do. Can someone help me?
It seems that you have declared the @property for the managed object context with the “copy” attribute. You should declare it as
A managed object context cannot be copied, but it would also make no sense. You want to use the same context in your class, not a (independent) copy.