I’m having issues setting the delegate of a Core Data object to a certain view controller I have. I’m getting and error which leads me to believe it’s not synthesizing the accessor methods:
2012-06-23 18:21:20.566 App[34164:12803] -[NSManagedObject setSyncDelegate:]: unrecognized selector sent to instance 0x907cf30
2012-06-23 18:21:20.567 App[34164:12803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject setSyncDelegate:]: unrecognized selector sent to instance 0x907cf30'
The NSManagedObject, SavedPhoto, has the following .h:
@interface SavedPhoto : NSManagedObject
@property (nonatomic, strong) NSString *fileName;
@property (nonatomic, strong) id<SyncPhotoDelegate> syncDelegate;
@end
and .m:
@implementation SavedPhoto
@dynamic fileName;
@synthesize syncDelegate = _syncDelegate;
@end
And I’m trying to set the delegate in a view controller like so:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
SavedPhoto *savedPhoto = (SavedPhoto *)[NSEntityDescription insertNewObjectForEntityForName:@"SavedPhoto" inManagedObjectContext:context];
[savedPhoto setSyncDelegate:self];
Where “self” is a view controller that implements the protocol SyncPhotoDelegate. Is it even possible to have a synthesized property in an NSManagedObject?
It looks like the instance is not actually one of your class. I would check your model file to make sure it is configured properly. Notice in your console output that it says
[NSManagedObject setSyncDelegate:]and not[SavedPhotosetSyncDelegate:]