asheyla asheyla - 8 months ago 25
Swift Question

How to save ViewController server data when coming back to it from another VC?

I have this line of events: the user goes into HomeViewController, taps on something, goes into another view controller and when he taps on the back bar button, he goes back to HomeViewController, of course.

Only that in this case I do not want to make again the request to the server, I just want to show it as it previously was. How can I do this?

I mention that I do my requests to server in viewWillAppear.


As the HomeViewController is not dismissed (at least in the way you described this), then there is no need to "save" anything.

The data should still be there.

My approach would be to move the server request code in your HomeViewController from ViewWillAppear() to ViewDidLoad().

Like that, a request will not be triggered again. And your data will still be there.

But your HomeViewController will never be refreshed again after you open the app.

If you want the HomeViewController to refresh (make another set of requests), why not do like the mail iPhone app ? (swiping down for 1 sec refreshes the VC).

This seems like a more elegant solution and a more cost-effective one. If it's good for Apple's email app, then it should be good for your app.

enter image description here