Search code examples
objective-cxcodensimage

problems with NSImage


I'm having problems with the use of the class NSImage. I'm trying to use the function initWithData: but it does not work (anything related to NSImage doesn't work). Here is a simple example of what im trying. The NSData data is right.

My project is a commandline tool of foundation type.

NSData *imdata =[[NSData alloc] initWithContentsOfFile:@"/Users/JulianDavid/Desktop/ecoli_20000.png"];
if(!imdata){
    NSLog(@"there is data");
}
NSImage *imag=[[NSImage alloc]initWithData:imdata];

Solution

  • The error

    Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_NSImage"
    

    means that the linker can't find the code implementing the NSImage class. According to the NSImage documentation, it's implemented in the AppKit framework. So, in order for the linker to link the code properly, you need to link against the AppKit framework. Do this by adding the AppKit framework into your Xcode project.