The error is in this line
NSEntityDescription *imageEntity = [NSEntityDescription entityForName:@"Thumbnail"
inManagedObjectContext:[context valueForKey:@"image"]];
You cannot apply valueForKey:@"image"
to a managed object context. You have to apply it to the fetched objects (or use the image
property of the fetched object).
Note also that executeFetchRequest:
returns nil
only if an error occurs. If no entities are found, it returns an empty array.
NSEntityDescription *imageEntity = [NSEntityDescription entityForName:@"Thumbnail" inManagedObjectContext:context];
[fetchRequest setEntity:imageEntity];
NSError *error;
NSArray * array = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (array == nil) {
NSLog(@"Testing: Fetch error: %@", error);
} else if ([array count] == 0) {
NSLog(@"Testing: No results found");
}else {
Thumbnail *testEntity = [array objectAtIndex:0];
NSImage *image = testEntity.image;
_coreDataImageView.image = image;
}