Cocoa NSAttributeString作为核心数据实体中的可转换属性
在核心数据编程指南的可转换属性下。 声明您现在可以像使用任何其他标准属性一样使用该属性,如以下代码片段所示: 下面列出的代码行是newEmployee.favoriteColor=[NSColor redColor]; 我试图在我的代码中做一些类似的事情,但它不起作用。这是我的密码: 在条目h中:Cocoa NSAttributeString作为核心数据实体中的可转换属性,cocoa,core-data,Cocoa,Core Data,在核心数据编程指南的可转换属性下。 声明您现在可以像使用任何其他标准属性一样使用该属性,如以下代码片段所示: 下面列出的代码行是newEmployee.favoriteColor=[NSColor redColor]; 我试图在我的代码中做一些类似的事情,但它不起作用。这是我的密码: 在条目h中: @interface Entry : NSManagedObject { } @property (nonatomic, retain) NSAttributedString * conten
@interface Entry : NSManagedObject
{
}
@property (nonatomic, retain) NSAttributedString * contentString;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSManagedObject * journal;
@end
在Entry.m中:
@implementation Entry
@dynamic contentString;
@dynamic date;
@dynamic journal;
- (void)awakeFromInsert {
[super awakeFromInsert];
self.date = [NSDate date];
}
@end
在其他地方,我有以下代码:
Entry *newEntry =
[NSEntityDescription insertNewObjectForEntityForName:@"Entry"
inManagedObjectContext:[self managedObjectContext]];
newEntry.contentString = [[[NSAttributedString alloc] initWithString:@"MyString"] autorelease];
newEntry.journal = self.journal;
线路
相当于
但据我所知,这不起作用。我得到一个运行时错误:
2010-10-13 09:02:08.577 JournalMaker[2437:a0f]无法创建NSData
来自NSConcreteAttributedString类的对象MyString{}
我不知道这个错误消息是什么意思。有人能解释一下吗?告诉我们您是如何对该属性进行建模的,这是本例中的重要信息。应该如何建模?我们将其设置为id,但我们尝试了NSAttributedString,但也没有成功。。。
newEntry.contentString = [[[NSAttributedString alloc] initWithString:@"MyString"] autorelease];
newEmployee.favoriteColor = [NSColor redColor];