Swift ios viewDidLoad or viewDidAppear

1.1k Views Asked by At

I am new to Swift and im not sure how I should go foward with this.

I have a table view that I populate with data from an external API.

Then if you press on one item/row in the tableview you will get directed to that items "detail" page.

When that happens I send some stuff with the prepareForSegue eg items title and some other info.

But once you hit the items detail page one more API call must be made in order to get out some more information about that item.

So my question now is:

Should I display the info coming with the prepareForSegue using viewDidLoad()

Then make the second API call inside the viewDidAppear() ?

My goal is to not let the user wait for the second API call, I already made API call nr1 inside the tableview and pushed that info when using prepareForSegue so that info should be ready directly when hitting the detail page.

Thanks in advance,

1

There are 1 best solutions below

0
On BEST ANSWER

You display whatever info you have in the viewDidLoad. Ideally you can have "Load More" button, which will further make the 2nd API call and update the view with fetched info.

If you want to make the 2nd API call automatically, just go ahead and add it in the viewDidLoad itself. Network call should be Asynchronous and should update the UI when data is fetched.