UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: List / Detail App

Forums > SwiftUI

I am writing an app that displays a list of items and when the user clicks one of the items on the list then I want it to display the details. Now I've done this where the call to the API for the list returns all the details I need for both the list and detail screens.

What I want to do now is to make two seperate calls to the API, one to get the list, and then once the user has selected an item from that list make a seperate call to the API to get the details.

My question is where to put the call to the API, in the ListView, the DetailView or in a third view?

2      

If you want to break-up the API calls, I would suggest you have an API call in your ListView's onAppear that will call the API to retreive the needed info for your ListView. In your DetailView you can have the API call for that item's details in it's onAppear.

2      

Hi @MrGLWatson

I understand that you want the list 'call' and and detail 'call' to be separate but every time the user goes to details then you will do another network call to get the details. I think you would be better off doing one network call and retriving it and cache it. If really big data then limit the amount of returns values then do another if user goes past that number.

I would of thought this may be better then doing lots of network calls to get details each time.

Maybe I havee got the wrong end of the stick and if you give more details then can be better information.

Nigel

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.