I would like to start by highlighting my views hierarchy. I just have FindUserView and WelcomeView.
FindUserView is used for retrieving users from the server if the entered email exists. If so, then it automatically redirects me to the next WelcomeView where I can enter password and login.
I've created a repo here and a video SwiftUI - Pop back does not deallocate view
My FindUserView: ---------------------------- and WelcomeView:
By pressing NEXT button on FindUserView I fetch a user from the database:
func fetchUser(with email: String) {
userService.getUser(with: email) { (result) in
switch result {
case .success(_):
self.showActivityIndicator = false
self.showingAlert = false
self.showWelcomeView = true
break
case .failure:
self.showingAlert = true
break
}
}
}
I use NavigationView and programatically show WelcomeView by changing showWelcomeView state above:
NavigationLink(destination: WelcomeView(), isActive: $showWelcomeView) { EmptyView() }
Now I am on welcome view WelcomeView.
But when I press this button and pop back, my WelcomeView still exists.
As I use @EnvironmentObject with observable property state I see how it reflects to the view which is already dismissed. Is this correct behaviour? Or do I need to dealloc WelcomeView somehow? Does it lead to memory leaks?
I am a bit worry as in UIKit when you pop back in navigation stack the view controller it is deallocated by UINavigationController by removing view controller from the array automatically. How to pop back correctly in SwiftUI?


