I need advice on best practice with Redux in iOS app.
I am trying to master this architectural pattern, but I am not using Redux+Reactive approach. Just ReSwift + simple declarative code.
The problem I am facing is basic. Storing UIImage
.
As far as I've seen in some tutorial, it is not advisable to store UIImage
as a state's property. Hence, it is recommended to store the path to the image.
To obtain the path, we need to save the image locally to disk. The image comes from phone's media library. So, saving it locally takes time (it is done synchronously, because I don't want to add async tasks for the simplest screen with one UIImageView
).
Fortunately, image picker controller provides us with the image url:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
let imageURL = info[.imageURL] as? URL
picker.dismiss(animated: true, completion: nil)
store.dispatch(DidPickImageAction(imageURL: imageURL))
}
I can use it, without rewriting image into the file, which solves the problem.
But, there is also option to make new image via camera. In that case info dictionary does not have .imageURL
, which again leads me to the necessity to write image to file.
This makes me want to just store UIImage
in state, but since it is against Redux rules, I am asking:
What is the best practice in working with images in Redux architecture?
Any help will be very much appreciated.