gpt4 book ai didi

ios - 找不到实体名称的 NSManagedObjectModel

转载 作者:行者123 更新时间:2023-11-29 04:38:43 26 4
gpt4 key购买 nike

我得到错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'CorePlaylist''

但不久前还有效!现在,我在 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];
}

最佳答案

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

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

关于ios - 找不到实体名称的 NSManagedObjectModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10699707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com