gpt4 book ai didi

iphone - NSInternalInconsistencyException 找不到实体名称的 NSManagedObjectModel

转载 作者:行者123 更新时间:2023-11-28 22:58:24 25 4
gpt4 key购买 nike

我正在尝试在我已经开始的项目中设置核心数据。我已经解决了一些其他错误,但现在已将范围缩小到这个,

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

我想我已经缩小了问题的范围,并找到了这个问答的可能解决方案 here回复:亚历克斯的回答。

但是我不完全确定这对我来说是这种情况,因为我感到困惑的原因是我没有在我的应用程序委托(delegate)和 View Controller 中设置所有内容,而是实际上使用我的应用程序委托(delegate)和对象类。所以我希望有人可以帮助我在这里隔离并解决我的问题......

这是我的对象类中的代码段,它给我带来了问题。它几乎与 xcode 为 coredata 应用程序生成的模板代码相同,但是它排除了排序和 tableview 的东西,因为我不需要那些。我只是将一堆 NSData 转储到我的 coredata 对象中。

- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
return __fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Manuf" inManagedObjectContext:self.managedObjectContext]; //this is the line where my code fails and generates the error in the log
[fetchRequest setEntity:entity];

// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}

return __fetchedResultsController;
}

更新:

这是我认为我出错的地方。在模板代码中, Controller 和上下文是这样在 appdelegate 中设置的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
ICDMasterViewController *controller = (ICDMasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}

因为我在一个对象类中做我所有的事情,所以我不确定如何在我的应用委托(delegate)中初始化它?

与我现在在我的 appdelegate 中尝试做的相反

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Add status bar
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

self.window.rootViewController = self.navigationController; //Adds RootViewController to the NavigationController interface
self.navigationController.navigationBar.tintColor = [UIColor grayColor];
[self.window makeKeyAndVisible];

//try setting up context for my nsobjectclass EngineResponses
EngineResponses *engineResponses = [[EngineResponses alloc] init];
engineResponses.managedObjectContext = self.managedObjectContext;

return YES;
}

最佳答案

早上好。

我会检查三件事:

1) 是 self.managedObjectContext nil 吗? (如果你 NSLog(@"%@", self.managedObjectContext); 会得到什么?

2) 您的模型描述是否包含名为 Manuf 的实体 - 它可能区分大小写:)

3) 创建协调器时,是否正确加载了 (2) 中的模型?

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

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