FROM : David Alter
DATE : Wed Jul 12 01:20:12 2006
I want to store NSImages in core data. To do this I did the following
1) In my data model I set the attribute type to be "Binary Data"
2) In the sub class of my NSManagedObject I added some methods
- (void)setArtwork:(NSImage *)value
{
[self willChangeValueForKey: @"artwork"];
[self setPrimitiveValue: value forKey: @"artwork"];
[self didChangeValueForKey: @"artwork"];
}
- (NSImage *)artwork
{
NSData * tmpValue;
[self willAccessValueForKey: @"artwork"];
tmpValue = [self primitiveValueForKey: @"artwork"];
[self didAccessValueForKey: @"artwork"];
return tmpValue;
}
- (void)willSave
{
NSImage *tmpImage = [self primitiveValueForKey:@"artwork"];
if (tmpImage != nil) {
[self setPrimitiveValue:[NSArchiver
archivedDataWithRootObject:tmpImage] forKey:@"artworkData"];
} else {
[self setPrimitiveValue:nil forKey:@"artworkData"];
}
[super willSave];
}
- (void)awakeFromFetch
{
NSData *imageData = [self valueForKey:@"artworkData"];
if (imageData != nil) {
NSImage *image = [NSUnarchiver
unarchiveObjectWithData:imageData];
[self setPrimitiveValue:image forKey:@"artwork"];
}
}
3) I did a quick interface in IB and used Binding to link things up .
4) The data gets loaded from and external data source the first time
the application runs.
When i run it and try to save the persistent store I get "This class
is not key value coding-compliant for the key artworkData" Do I need
to have a "setArtworkData:(NSData*)" and "(NSData*)artworkData"
method in my subclass of NSManagedObject? Or is there another peace
of this I'm missing.
thanks for the help
-dave
DATE : Wed Jul 12 01:20:12 2006
I want to store NSImages in core data. To do this I did the following
1) In my data model I set the attribute type to be "Binary Data"
2) In the sub class of my NSManagedObject I added some methods
- (void)setArtwork:(NSImage *)value
{
[self willChangeValueForKey: @"artwork"];
[self setPrimitiveValue: value forKey: @"artwork"];
[self didChangeValueForKey: @"artwork"];
}
- (NSImage *)artwork
{
NSData * tmpValue;
[self willAccessValueForKey: @"artwork"];
tmpValue = [self primitiveValueForKey: @"artwork"];
[self didAccessValueForKey: @"artwork"];
return tmpValue;
}
- (void)willSave
{
NSImage *tmpImage = [self primitiveValueForKey:@"artwork"];
if (tmpImage != nil) {
[self setPrimitiveValue:[NSArchiver
archivedDataWithRootObject:tmpImage] forKey:@"artworkData"];
} else {
[self setPrimitiveValue:nil forKey:@"artworkData"];
}
[super willSave];
}
- (void)awakeFromFetch
{
NSData *imageData = [self valueForKey:@"artworkData"];
if (imageData != nil) {
NSImage *image = [NSUnarchiver
unarchiveObjectWithData:imageData];
[self setPrimitiveValue:image forKey:@"artwork"];
}
}
3) I did a quick interface in IB and used Binding to link things up .
4) The data gets loaded from and external data source the first time
the application runs.
When i run it and try to save the persistent store I get "This class
is not key value coding-compliant for the key artworkData" Do I need
to have a "setArtworkData:(NSData*)" and "(NSData*)artworkData"
method in my subclass of NSManagedObject? Or is there another peace
of this I'm missing.
thanks for the help
-dave
| Related mails | Author | Date |
|---|---|---|
| David Alter | Jul 12, 01:20 | |
| mmalc crawford | Jul 12, 02:01 |






Cocoa mail archive

