I have two views written in swiftUI , say for example ViewA and ViewB. onAppear() of ViewA has an apiCall which calls when initially the view is loaded. I navigate to ViewB from ViewA using navigation link and on clicking back button in ViewB the onAppear() of ViewA is called.
• Is there any way to stop calling onAppear() while navigated back from a view
• I am looking swiftUI for something like 'ViewDidLoad' in UIKit given a sample of my code
struct ContentView: View {
var body: some View {
NavigationView{
List(viewModel.list){ item in
NavigationLink(
destination: Text("Destination"),
label: {
Text(item.name)
})
}
.onAppear{
viewModel.getListApiCall()
}
}
}
}
viewModel.list
is empty? – MantonviewModel.getListApiCall()
in the parent view, once (actual code depends on what exactly theviewModel
is, i.e. where is it declared). – Stoat