I have a simple model object Location with a few text items and a images : [UIImages]?. Location is Codable so I store the text bits as JSON and then write the images into the same FileWrapper.
My question is how to store the relationship between the image files and the [UIImage] array. The images have to come back in the same order. Is there a way I can hook into Coding so that the array gets replaced by the URLs pointing to the images?
Or alternately, should I always have the images as separate files, say in the cache directory, and replace the [UIImage] with [URL]s
Here's an example of storing a bunch of image files in a file wrapper, along with an "index" (which I call
list) of their names in a specific order:And here's an example of reading that file wrapper by fetching the list and then getting the image files by name in that same order:
That prints:
All you want to do in UIDocument is that same thing, except that UIDocument will write and read the file wrapper for you.