How to save array of UIImages?

I have array:
Code Block
var imgs: [UIImage] = userDefaults.object(forKey: "myKey") as? [UIImage] ?? []

How I can save it?

Answered by Claude31 in 654245022
Where do you want to save ?
To a file ?
Maybe the best is to save each image on an individual file, that will make retrieving, removing… simpler.

In that case:
You can convert images:

Code Block
for img in imgs {
let imageData = img.pngData()
let fileName = // Create a file name for each image ; for instance from the name of the image
fileManager.createFile(atPath: fileName, contents: imageData, attributes: nil)
}


Accepted Answer
Where do you want to save ?
To a file ?
Maybe the best is to save each image on an individual file, that will make retrieving, removing… simpler.

In that case:
You can convert images:

Code Block
for img in imgs {
let imageData = img.pngData()
let fileName = // Create a file name for each image ; for instance from the name of the image
fileManager.createFile(atPath: fileName, contents: imageData, attributes: nil)
}


How to save array of UIImages?
 
 
Q