Objective c Can';t将属性设置为NSManagedObject

Objective c Can';t将属性设置为NSManagedObject,objective-c,core-data,Objective C,Core Data,我对使用核心数据很陌生。 我有Chat类(NSManagedObject的子类),我需要用它创建新对象 #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @interface Chat : NSManagedObject @property (nonatomic, retain) NSString *chatID; @property (nonatomic, retain) NSString

我对使用核心数据很陌生。 我有Chat类(NSManagedObject的子类),我需要用它创建新对象

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@interface Chat : NSManagedObject

@property (nonatomic, retain) NSString *chatID;
@property (nonatomic, retain) NSString *modified;
@property (nonatomic, retain) NSString *opponentID;
@property (nonatomic, retain) NSString *opponentFacebookID;
@property (nonatomic, retain) NSString *opponentName;
@property (nonatomic, retain) NSString *lastMessage;

@end

#import "Chat.h"

@implementation Chat

@dynamic chatID;
@dynamic modified;
@dynamic opponentID;
@dynamic opponentFacebookID;
@dynamic opponentName;
@dynamic lastMessage;

- (id)init {
    if (self = [super init])
    {
    }
    return self;
}

@end
但是我的应用程序在设置
chat.chatId
时崩溃。它向我显示了这个错误,但我不知道如何修复它

2013-06-18 12:01:25.625 MyApp[5477:907] -[Chat setChatID:]: unrecognized selector sent to instance 0x1d8661d0
2013-06-18 12:01:25.627 MyApp[5477:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Chat setChatID:]: unrecognized selector sent to instance 0x1d8661d0'

这可能意味着
chatID
不是 核心数据模型检查器

我总是建议让Xcode(或“mogenerator”之类的工具)生成托管对象子类文件
而不是“手动”写入它们。

无法识别的选择器意味着应用程序试图告诉对象执行它没有的功能(例如,试图修改标签的图像,它没有图像属性,因此会抛出无法识别的选择器)。在错误消息中,它试图使用不存在的setChatID。我在这台计算机上没有我的xcode项目,因此我无法检查我的核心数据样本,但我建议重新创建聊天对象,并使用GUI创建所需的属性,然后自动创建类。如果您想让我提供更多帮助,请告诉我,今天晚些时候我有另一台计算机时,我会再次检查。

请摆脱
init
方法。也会有帮助you@Alladinian:你是对的,那也可能导致问题。就是这样!我的模型具有不同的属性名称。我又自动生成了这个类!谢谢
2013-06-18 12:01:25.625 MyApp[5477:907] -[Chat setChatID:]: unrecognized selector sent to instance 0x1d8661d0
2013-06-18 12:01:25.627 MyApp[5477:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Chat setChatID:]: unrecognized selector sent to instance 0x1d8661d0'