I'm trying to save a UIImage
to NSData
and then read the NSData
back to a new UIImage
in Swift. To convert the UIImage
to NSData
I'm using the following code:
let imageData: NSData = UIImagePNGRepresentation(myImage)
How do I convert imageData
(i.e., NSData
) back to a new UIImage
?
To save as data:
From StoryBoard, if you want to save "image" data on the imageView of MainStoryBoard, following codes will work.
To load "image" to imageView: Look at exclamation point "!", "?" closely whether that is quite same as this one.
"NSData" type is converted into "Data" type automatically during this process.