gpt4 book ai didi

ios - 'NSInvalidArgumentException',原因 : 'keypath Patient.nachname not found in entity '

转载 作者:行者123 更新时间:2023-11-29 12:54:56 30 4
gpt4 key购买 nike

为什么我会收到 NSInvalidArgumentException?

我的 TableView Controller 代码:

- (NSFetchedResultsController *)fetchedResultsController {

CoreDataHelper *cdh = [(MRMedSafeAppDelegate *) [[UIApplication sharedApplication] delegate] cdh];

if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Patient" inManagedObjectContext:cdh.context];
[fetchRequest setEntity:entity];

NSSortDescriptor *sort1 = [[NSSortDescriptor alloc]
initWithKey:@"Patient.nachname" ascending:YES];
NSSortDescriptor *sort2 = [[NSSortDescriptor alloc]
initWithKey:@"Patient.vorname" ascending:YES];

[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort1, sort2, nil]];

[fetchRequest setFetchBatchSize:20];

NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:cdh.context
sectionNameKeyPath:nil
cacheName:nil];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;

return _fetchedResultsController;

我的病人.h:

@interface Patient : NSManagedObject
@property (nonatomic, retain) NSDate * geburtsdatum;
@property (nonatomic, retain) NSString * nachname;
@property (nonatomic, retain) NSString * vorname;
@property (nonatomic, retain) NSNumber * weiblich;
@end

我的病人.m:

#import "Patient.h"
@implementation Patient
@dynamic geburtsdatum;
@dynamic nachname;
@dynamic vorname;
@dynamic weiblich;
@end

由 XCode 5 从 Model.xcdatamodeld 文件中生成的 Patient.h 和 Patient.h。

为什么我得到异常?

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath Patient.nachname not found in entity '

患者是唯一的类,没有其他模型类,模型中也没有关系。

最佳答案

只需在

中使用“nachname”而不是“Patient.nachname”
NSSortDescriptor  *sort1 = [[NSSortDescriptor  alloc]
initWithKey:@"Patient.nachname" ascending:YES];

即应该是

NSSortDescriptor  *sort1 = [[NSSortDescriptor  alloc]
initWithKey:@"nachname" ascending:YES];

下一个排序描述符和“vorname”也是如此。

关于ios - 'NSInvalidArgumentException',原因 : 'keypath Patient.nachname not found in entity <NSSQLEntity Patient id=1>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21392854/

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