Core Data and Search / Filter Fields
Core Data and Search / Filter Fields
- Subject: Core Data and Search / Filter Fields
- From: ChrisB <email@hidden>
- Date: Wed, 13 Sep 2006 11:26:45 -0700
I set up a Core Data project that works great. Then using an
"Advanced Core Data" tutorial and the Docs as a guide, I
subclassed the NSManagedObject and created my own accessor methods for
a couple of items.
Basically in my getter method I want return a default object (in this
case an image) if the data is NULL. But I want to do this without
adding the image binary to the data store. Here are my two accessors.
- (NSImage *)mediaIcon
{
NSLog(@"get mediaIcon");
[self willAccessValueForKey:@"mediaIcon"];
NSImage *aIcon;
NSData *iconData = [self primitiveValueForKey:@"mediaIcon"];
if (iconData != NULL) {
NSLog(@"Found an image... returning it");
aIcon = [NSKeyedUnarchiver unarchiveObjectWithData:iconData];
} else {
NSLog(@"No image found... return a default");
// aIcon = [NSImage imageNamed:@"NSApplicationIcon"]; // does not
work. why not?
aIcon = nil; // at least everything works, but this is not what I
want.
}
[self didAccessValueForKey:@"mediaIcon"];
return aIcon;
}
- (void)setMediaIcon:(NSImage *)aIcon
{
NSLog(@"setting mediaIcon");
[self willChangeValueForKey:@"mediaIcon"];
[self setPrimitiveValue:[NSKeyedArchiver
archivedDataWithRootObject:aIcon] forKey:@"mediaIcon"];
[self didChangeValueForKey:@"mediaIcon"];
}
When using the :
aIcon = [NSImage imageNamed:@"NSApplicationIcon"];
The log returns this followed by memory address. The same image
assignment used elsewhere in the code as a test works perfectly.
*** NSRunLoop ignoring exception 'Cannot create NSData from object
NSImage
What am I missing about how this works?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden