Adeline
Adeline

Reputation: 475

Bridging NSImage and UIImage

I have an iphone application that can be enriched with additional content downloadable in the form of packages.

This additional content (packages) is built using a MAC OS application.

The MAC OS application is used to gather resources and artwork, do the layout, and create the package.

Some of the package contains serialized objects (NSCoder), amongst which are NSImage objects.

My issue is : NSImage does not exist on iPhone.

Is it possible to deserialize an NSImage into an UIImage ?

Upvotes: 1

Views: 686

Answers (2)

Aman
Aman

Reputation: 241

Convert NSImage to NSData and then this NSData is to UIImage. NOTE : Save image data to file to read from it

MAC CODE
NSData *imageData = [self.someImage TIFFRepresentation];

iOS CODE
UIImage *image = [UIImage imageWithData: imageData];

Upvotes: 2

Matteo Pacini
Matteo Pacini

Reputation: 22846

You could store the images as Data (it is Encodable) on macOS, and then instantiate the UIImage on iOS by doing:

let image = UIImage(data: yourData) // yields UIImage?

Upvotes: 1

Related Questions