Nick Balistreri Nick Balistreri - 1 year ago 93
Objective-C Question

What is the equivalent of UIImage imageWithData for NSImage

I want to load an image into my MAC OS desktop application. I have found plenty of documentation on how to do this on mobile iOS but how do I load the image on my desktop app since there is no UIImage(imageWithData).

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:@"myurl"]];
productImage.image = [NSImage imageWithData:imageData];

Answer Source

imageWithData: is a convenience initializer for initWithData: in UIKIt. AppKit doesn't seem to have this, so you'll just need to use initWithData: like this:

productImage.image = [[NSImage alloc] initWithData:imageData];

See this page for more info:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download