【发布时间】:2014-11-26 22:04:40
【问题描述】:
我有一个名为 Country 的核心数据实体。该实体有一个名为 nameOfCountry 的字段,其中包含英文国家名称。我需要将其本地化为其他语言,因此我创建了一个名为 nameOfCountryLocalized 的临时属性。
在 Country 类中我正在导入此类别
Countries+NameOfCountryLocalized.h
#import "Countries.h"
@interface Countries (NameOfCountryLocalized)
@property (nonatomic, strong) NSString * nameOfCountryLocalized;
@end
Countries+NameOfCountryLocalized.m
#import "Countries+NameOfCountryLocalized.h"
#import "Countries.h"
@implementation Countries (NameOfCountryLocalized)
@dynamic nameOfCountryLocalized;
-(NSString *) nameOfCountryLocalized {
[self willAccessValueForKey:@"nameOfCountryLocalized"];
NSString *nameLocalized = NSLocalizedString(self.nomePais, nil);
[self didAccessValueForKey:@"nameOfCountryLocalized"];
return nomeLocalizado;
}
-(void)setNameOfCountryLocalized:(NSString *) nameLocalized {
[self willChangeValueForKey:@"nameOfCountryLocalized"];
[self setNomePaisLocalizado:];
[self didChangeValueForKey:@"nameOfCountryLocalized"];
}
@end
当我尝试从 tableViewController 使用它访问 nameOfCountryLocalized 时
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Countries" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"nameOfCountryLocalized" ascending:YES];
[fetchRequest setSortDescriptors:@[sort]];
[fetchRequest setFetchBatchSize:20];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:@"Root"];
_fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
我看到这个错误:keypath nameOfCountryLocalized not found in entity
有什么线索吗?
【问题讨论】:
标签: ios cocoa-touch core-data nsmanagedobject nsfetchedresultscontroller