Nick Balistreri
Nick Balistreri

Reputation: 131

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];

Upvotes: 0

Views: 1371

Answers (1)

Mean Dinosaur
Mean Dinosaur

Reputation: 386

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: https://developer.apple.com/reference/appkit/nsimage/1519941-initwithdata?language=objc

Upvotes: 5

Related Questions