I am trying to make a simple document-based cocoa application that can save and load images in pdf files.
For the save part, I am using
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
return [imageView dataWithPDFInsideRect:[imageView bounds]];
}
And this works, the image could be saved to a PDF file.
For the load part, I am using
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
NSData *dataFromFile = [data retain];
NSImage *image = [[NSImage alloc] initWithData:dataFromFile];
NSLog(@"Load image as: %@", image);
// Do something about the image
if (outError != NULL) {
NSLog(@"Error when loading data ...");
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
return NO;
}
return YES;
}
This always fails, but the NSLog prints out that the image is not NULL:
Load image as: NSImage 0x16ead890 Size={1023, 601} Reps=(NSPDFImageRep 0x16e97480 Size={1023, 601} ColorSpace=NSCalibrateRGBColorSpace BPS=0 Pixels=1023x601 Alpha=NO)
Error when loading data ...
I don't quite understand what problem happens in the readFromData that makes outError != NULL here.