Nick Balistreri Nick Balistreri - 5 months ago 39
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];


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: