onAppear & onDisappear
#modifier
The onAppear and onDisappear modifiers are extremely convenient methods that let us call functions when specific components appear or disappear from the screen. These are often used for managing animations and loading data in SwiftUI applications.
Create a nav stack with string var
Add onAppear Modifier
myText var value gets changed, because we are watching the screen.
Add a delay to modifier
We can add dispatchQueue to make .onAppear modifier works after 5 seconds.
onDisappear
onDisappear won’t be shown, because modifier works after user leaves the screen.
Usually to clear the function that aren’t visible is the main purpose of this modifier.
Adding a lazy V Stack
for the larger data set, it’s smarter to use the lazy stack.
by writing .onAppear{} we can skip the perform part.