我得到错误:
由于未捕获的异常“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];
}