在实体中找不到瞬态属性
我正在尝试从预填充的 sqlite 数据库中获取属性(作者)的第一个字母。我使用 coredata 从数据库检索数据没有问题。但是,当我尝试从瞬态属性获取数据时,我收到此错误消息:“NSFetchedResultsController ERROR: object { Autor = "\U00cdtalo Calvino"; } returned nil value for section name key path 'FirstLetter'。对象将被放置在未命名部分”...
我在我的实体 Cit 中创建了一个名为 FirstLetter 的瞬态属性。我还定义了实体的类。
Cit.h
@interface Cit : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * Autor;
@property (nonatomic, retain) NSString * FirstLetter;
- (NSString *) FirstLetter;
@end
Cit.m
#import "Cit.h"
@implementation Cit
@dynamic Autor;
@dynamic FirstLetter;
- (NSString *) FirstLetter {
NSLog(@"doing");
[self willAccessValueForKey:@"FirstLetter"];
NSString * initial = [[self valueForKey:@"Autor"] substringToIndex:1];
[self didAccessValueForKey:@"FirstLetter"];
return initial;
}
@end
我无法让它工作。有人有解决办法吗???谢谢!
I'm trying to get the first letter of an attribute (autor) from my pre populated sqlite database. I have no problems retriving data from the database using coredata. But when I try to get data from my transient property, I get this error message: "NSFetchedResultsController ERROR: object { Autor = "\U00cdtalo Calvino"; } returned nil value for section name key path 'FirstLetter'. Object will be placed in unnamed section"...
I have created a transient attribute called FirstLetter and inside my entity Cit. I have also my class for the entity defined.
Cit.h
@interface Cit : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * Autor;
@property (nonatomic, retain) NSString * FirstLetter;
- (NSString *) FirstLetter;
@end
Cit.m
#import "Cit.h"
@implementation Cit
@dynamic Autor;
@dynamic FirstLetter;
- (NSString *) FirstLetter {
NSLog(@"doing");
[self willAccessValueForKey:@"FirstLetter"];
NSString * initial = [[self valueForKey:@"Autor"] substringToIndex:1];
[self didAccessValueForKey:@"FirstLetter"];
return initial;
}
@end
I cannot get the it to work. Does anyone have a solution for that??? thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在模型类中做了类似的事情,但我没有费心在模型中创建瞬态对象。我刚刚向我的模型添加了一个
- (NSString *)sectionIndex
方法,该方法返回字符串的第一个字母,与您相同。因此,我会尝试从模型中删除瞬态属性,看看是否效果更好。
I did something similar in my model class, but I didn't bother creating a transient object in the model. I just added a
- (NSString *)sectionIndex
method to my model that returned the first letter of the string, same as you.So, I'd try deleting the transient attribute from your model and see if that works any better.