Reputation: 21
I am following a tutorial on preloading an existing database into core data. the code compiles fine until I get to this line:
NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"FailedBankInfo" inManagedObjectContext:context];
where it returns the following error: 2012-11-19 12:45:02.247 CoreDatTutorial2[2049:403] -[FailedBankInfo subentitiesByName]: unrecognized selector sent to instance 0x100301010'
I've checked to make sure the is not empty and that it has been saved into the the product directory. Any idea what I'm doing wrong? If I comment out that line of code, the project compiles without a problem.
here's the rest of the code:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription insertNewObjectForEntityForName:@"FailedBankInfo" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (FailedBankInfo *info in fetchedObjects){
{
Upvotes: 0
Views: 153
Reputation: 539955
insertNewObjectForEntityForName:inManagedObjectContext:
creates a new managed object and inserts it into the managed object context. In particular, it returns an object of the class FailedBankInfo
(in your case), and not a NSEntityDescription
.
To create a NSEntityDescription
, use entityForName:inManagedObjectContext:
:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FailedBankInfo"
inManagedObjectContext:context];
[fetchRequest setEntity:entity];
Note that (starting with iOS 5.0) you can simplify this to
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"FailedBankInfo"];
Upvotes: 2