gpt4 book ai didi

objective-c - 核心数据崩溃 : Keypath Project not found in entity

转载 作者:行者123 更新时间:2023-12-03 22:54:16 32 4
gpt4 key购买 nike

- (void)fetchResult
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"Project" ascending:YES];

[request setEntity:self.entityDescription];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
self.fetchResultController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

NSError *fetchError = nil;
BOOL success = [self.fetchResultController performFetch:&fetchError];
if (success) {
NSLog(@"fetched!");
}
else {
NSLog(@"fetch fail!");
}
}

entityDescription 和上下文在 viewDidLoad 方法中设置,如下所示:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
self.entityDescription = [NSEntityDescription entityForName:@"Project" inManagedObjectContext:self.managedObjectContext];

崩溃信息:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“实体中未找到关键路径项目”

有人可以帮忙吗?;)

最佳答案

排序描述符中使用的键

[NSSortDescriptor sortDescriptorWithKey:@"Project" ascending:YES];

必须是 Core Data 实体的属性,而不是实体本身的名称。
所以你应该用一些属性替换排序描述符中的 @"Project"项目实体,例如 @"name"

关于objective-c - 核心数据崩溃 : Keypath Project not found in entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16331034/

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