NSAttributedString as a Transformable Attribute in Core Data Entity
In the Core Data Programming Guide under "Transformable Attributes" here. It is stated "You can now use the attribute as you would any other standard attribute, as illustrated in the following code fragment:"
The follow line of code is listednewEmployee.favoriteColor = [NSColor redColor];
I am trying to do something similar in my code but it doesn't work. Here is my code:
In Entry.h:@interface Entry : NSManagedObject
{
}
@property (nonatomic, retain) NSAttributedString * contentString;
@property (nonatomic, retain) NSDate * date;
@property (nonatomic, retain) NSManagedObject * journal;
@end
and in Entry.m:
@implementation Entry
@dynamic contentString;
@dynamic date;
@dynamic journal;
- (void)awakeFromInsert {
[super awakeFromInsert];
self.date = [NSDate date];
}
@end
Elsewhere I have this code:
Entry *newEntry =
[NSEntityDescription insertNewObjectForEntityFor开发者_运维知识库Name:@"Entry"
inManagedObjectContext:[self managedObjectContext]];
newEntry.contentString = [[[NSAttributedString alloc] initWithString:@"MyString"] autorelease];
newEntry.journal = self.journal;
The line
newEntry.contentString = [[[NSAttributedString alloc] initWithString:@"MyString"] autorelease];
is equivalent to
newEmployee.favoriteColor = [NSColor redColor];
As far as I can tell however this doesn't work. I get a runtime error:
I have no idea what this error message is supposed to mean. Can someone explain?2010-10-13 09:02:08.577 JournalMaker[2437:a0f] Cannot create NSData from object MyString{ } of class NSConcreteAttributedString
精彩评论