could not locate an NSManagedObjectModel for entity name

前端 未结 7 2529
[愿得一人]
[愿得一人] 2020-12-18 19:15

This is the code for toggleAddProject method, the Core Data code is almost the same as found in Apple\'s CoreDataBooks sample, however when I click the add button the app cr

7条回答
  •  我在风中等你
    2020-12-18 19:32

    Ok I ran across this issue as well and I solved it thusly. The original code was given as:

    Event *event = (Event *)[NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:managedObjectContext];
    

    While the code is concise it seems like the debugger can't display more detailed information about where the error is since you are both creating and configuring a new instance of the 'Event' entity (or whatever your Entity is named).

    Instead I broke out this into three lines and the debugger displayed a lot more information:

    Event *event = [[NSManagedObject alloc] init];
    NSManagedObjectContext *moc = [self managedObjectContext];
    event = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:moc];
    

    I found I had not set the correct Type for one of the attributes and I had a typo in my code, all of which the debugger pointed out.

提交回复
热议问题