I have two classes, a subclass of NSDocument (Class A) and a subclass of NSView (Class B). In my NSView subclass, after all the drawing is done, I save the view into a NSData. In Class B drawRect:
self.viewData = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:[self bounds]]TIFFRepresentation];
Setting a breakpoint on the next line shows the value :
_viewData OS_dispatch_data * 1003522 bytes 0x0000618000069cc0
However, in dataOfType:error: in Class A, the following line: (note that Class B is named theCanvas here)
return [[[NSBitmapImageRep alloc]initWithData:[theCanvas viewData]]representationUsingType:NSPNGFileType properties:nil];
results in an error:
ImageIO: CGImageSourceCreateWithData data parameter is nil
And a breakpoint in that method shows that viewData is nil:
_viewData NSData * nil 0x0000000000000000
Am I missing something here?
You need to ensure that theCanvas
actually points to the instance of your class where you know the data is being set correctly. The likelihood is that you have two different instances of the same class.