0

我在将 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 中拥有综合属性吗?

4

1 回答 1

3

看起来该实例实际上不是您的班级之一。我会检查您的模型文件以确保其配置正确。请注意,在您的控制台输出中它说的是[NSManagedObject setSyncDelegate:]不是 [SavedPhoto setSyncDelegate:]

于 2012-06-24T01:39:31.650 回答