【发布时间】:2014-01-27 22:17:32
【问题描述】:
为什么我会收到 NSInvalidArgumentException?
我的表格视图控制器代码:
- (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。
为什么我会遇到异常?
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“keypath Patient.nachname not found in entity”
Patient 是唯一的类,模型中没有其他模型类,也没有关系。
【问题讨论】:
标签: ios core-data nsfetchedresultscontroller