G
G
Gleb2021-08-27 16:03:01
Swift
Gleb, 2021-08-27 16:03:01

How to save Image in UserDefaults?

I get an image from the network by url, then I display it as a UIImage.
I wanted to make sure that when the Internet was turned off, the previously downloaded pictures were saved and questions arose.

1) Do I need to convert the image to jpeg? For some reason, in the guides I saw only this way.
2) Where should we populate and retrieve data to/from UserDefaults? (I'm using tableView) In a function that configures a UIImage to display in a cell? or a tableView delegate method like didSelectRowAt?

ps Maybe these are stupid questions, but this is the first time I've encountered UserDefaults.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kerimov, 2021-10-14
@shevzoom

The image definitely does not need to be saved to UserDefaults
AND the image does not need to be saved to the database
Only to a file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question