Your new code cannot work, because you mix class and instance methods.
Please explain what you mean. Here's what the developer documentation says about 'NSImage initWithData':
---------------------------------------->>>
initWithData:
Initializes and returns an NSImage instance with the contents of the specified NSData object.
- (id)initWithData:(NSData *)data
Parameters
data -- The data object containing the image data.
Return Value -- An initialized NSImage instance, or nil if the method cannot create an image representation from the contents of the specified data object.
Availability -- Available in Mac OS X v10.0 and later.
Declared In NSImage.h
<<<--------------------
Does this not indicate that NSImage is to be initialized with NSData?