找不到实体名称的NSManagedObjectModel

时间:2012-05-22 09:56:55

标签: ios core-data

我收到错误:

  

由于未捕获的异常而终止应用   'NSInternalInconsistencyException',原因:'+ entityForName:不能   找到实体名称'CorePlaylist''

的NSManagedObjectModel

但它前一段时间有效!现在我在didFinishLaunchingWithOptions终止之前收到了错误。

我的代码是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    NSLog(@"DID finish launching %@", [self managedObjectContext]);

    PlaylistsViewController *table = [[PlaylistsViewController alloc] init];

    NSManagedObjectContext *context = [self managedObjectContext];

    if (!context) {
        NSLog(@"\nCould not create *context for self");
    }

    table.context = context;

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

    return YES;
}

编辑:

-(void) getData {
context = [(ClientAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"CorePlaylist" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setFetchBatchSize:20];
[request setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"playlistid" ascending:YES];

NSArray *newArray = [NSArray arrayWithObject:sort];

[request setSortDescriptors:newArray];

NSError *error;

NSMutableArray *results = [[context executeFetchRequest:request error:&error] mutableCopy];

[self setArr:results];

[self.tableView reloadData];
}

1 个答案:

答案 0 :(得分:1)

确保您的coreDataModel文件位于项目中,并且您正在调用的实体拼写正确(区分大小写)。

如果您正在对设备进行测试,则可能需要完全删除要再次部署它的应用程序,以防止数据库问题损坏。