Reputation: 1437
I'm new using Core Data. I have the class Chat (subclass of NSManagedObject) and I need to create new objects with it.
#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
I insert the objects like this:
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"];
but my application crashes when setting chat.chatId
. It shows me this error and can't figure out what to do to fix it!
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'
Upvotes: 2
Views: 1540
Reputation: 456
unrecognized selector means the app tried to tell an object to do a function which it does not have (for example, trying to modify a label's image, it doesn't have an image attribute so it will throw a unrecognized selector). In the error message, it tried to use setChatID, which does not exist. I don't have my xcode projects on this computer so I can't check my core data samples, but I would suggest remaking the Chat object and using the GUI to create the attributes you need then create the class automatically. Let me know if you want me to help more and I will check again later today when I have my other computer.
Upvotes: 1
Reputation: 539755
That probably means that chatID
is not the actual name of the property as defined in the
Core Data Model inspector.
I would always recommend to let Xcode (or tools like "mogenerator") generate the managed object subclass files instead of writing them "manually".
Upvotes: 1