Helo, I’m still newbie with Core Data and suddenly stuck in these simple code:
Purchased* newItem=[NSEntityDescription insertNewObjectForEntityForName:@"Purchased" inManagedObjectContext:self.managedObjectContext];
[newItem setPurchasedDate:[NSDate date]];
[newItem setLastOpen:[NSDate date]];
if ([self.managedObjectContext save:&error])
{
//do something if the save success
}
Well, from the code above I’ve Got an ‘NSInvalidArgumentException’, reason: ‘-[Purchased setPurchasedDate:]: unrecognized selector sent to instance. As we can see the exception is pointing at
[newItem setPurchasedDate:[NSDate date]];
and that is right. When I try to debug this code step by step, the program just abort when this message is invoked.
I wonder why, cause there is no wrong in my model and my Purchased class, I’ve checked it hundred times. I have tried to change the location of setting value by overwrite -(void)awakeFromInsert() method and it’s fire the same exception. Is anyone has a suggestion? thanks before.
Check this:
Your managed object model’s
Purchasedentity has an attribute of typeDatethat is calledpurchasedDate, and another one calledlastOpen.In your
Purchased.hfile you haveIn your
Purchased.mfile you haveMake sure you
#import "Purchased.h"in the file where you create the new instance.