저는 Core Data를 사용하여 새로 왔습니다. 클래스 (NSManagedObject의 하위 클래스) 채팅 및 새 개체를 만들어야합니다.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 *chat = (Chat *)[NSEntityDescription insertNewObjectForEntityForName:@"Chat" inManagedObjectContext:[[DataManager sharedInstance] managedObjectContext]];
chat.chatID = [chatDict objectForKey:@"id"];
chat.modified = [chatDict objectForKey:@"modified"];
chat.lastMessage = [chatDict objectForKey:@"last_message"];
하지만 내 응용 프로그램이 충돌 chat.chatId
설정. 그것은 나에게이 오류를 보여주고 그것을 해결하기 위해 무엇을해야 하는지를 알 수 없다! 아마도 코어 데이터 모델 관리자에 정의 된 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'
'init' 메소드를 제거하십시오. [이 답변] (http://stackoverflow.com/questions/10489578/custom-initializer-for-an-nsmanagedobject)도 도움이 될 것입니다 – Alladinian
@Alladinian : 당신 말이 맞아요, 그 또한 문제를 일으킬 수 있습니다. –