0

I'm loading products for my app from Network every time the user opens an app.

My viewDidLoad looks like this:

override func viewDidLoad() {
    super.viewDidLoad()

    viewModel.loadProducts()
}

loadProducts func loads an Array of products

let products: [Product]

I want my app to save the previous array so in case of loadProducts() fails I will initialize products from phone local storage.

What are my steps to achieve that? and is it hard to do?

  • No, it's not that hard. If your only reason for doing this is to have a local backup to load then I would suggest storing the products array to a local (json) file. [Here](https://stackoverflow.com/questions/28768015/how-to-save-an-array-as-a-json-file-in-swift) is a question that could be helpful if you choose this solution. – Joakim Danielson Feb 15 '22 at 13:22

0 Answers0