How to save image picked using UIImagePickerController to png file?

When I use UIImagePickerController and pick an image, in what format is the UIImage object returned as the value of the UIImagePickerControllerOriginalImage key in userInfo? I need to save the UIImage object to a png file. How would I make sure the object is saved as a png file. There is the pngData() method of the UIImage class, but that is of type Data. How would I use that?

Replies

Use the write(to:options:) method on Data to write it to an appropriate URL.