在实体中找不到瞬态属性

发布于 2024-11-03 01:27:50 字数 927 浏览 4 评论 0原文

我正在尝试从预填充的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自演自醉 2024-11-10 01:27:50

我在模型类中做了类似的事情,但我没有费心在模型中创建瞬态对象。我刚刚向我的模型添加了一个 - (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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文