设置NSManagedObject的委托

时间:2012-06-24 01:36:13

标签: iphone ios

我在将Core Data对象的委托设置为我拥有的某个视图控制器时遇到问题。我收到并且错误导致我相信它没有合成访问器方法:

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'

NSManagedObject,SavedPhoto,具有以下.h:

@interface SavedPhoto : NSManagedObject

@property (nonatomic, strong) NSString *fileName;
@property (nonatomic, strong) id<SyncPhotoDelegate> syncDelegate;

@end

和.m:

@implementation SavedPhoto

@dynamic fileName;
@synthesize syncDelegate = _syncDelegate;

@end

我正在尝试在视图控制器中设置委托,如下所示:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
SavedPhoto *savedPhoto = (SavedPhoto *)[NSEntityDescription insertNewObjectForEntityForName:@"SavedPhoto" inManagedObjectContext:context];
[savedPhoto setSyncDelegate:self];

其中“self”是实现协议SyncPhotoDelegate的视图控制器。甚至可以在NSManagedObject中使用合成属性吗?

1 个答案:

答案 0 :(得分:3)

看起来实例实际上并不属于您的类。我会检查你的模型文件,以确保它配置正确。请注意,在您的控制台输出中,它显示[NSManagedObject setSyncDelegate:]不是 [SavedPhoto setSyncDelegate:]