Created
July 16, 2020 08:24
-
-
Save mbuchetics/45130b5c758d87429c226caa271dc4a4 to your computer and use it in GitHub Desktop.
SwiftUI view lifecycle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
let items = ["a", "b", "c"] | |
var body: some View { | |
NavigationView { | |
List { | |
ForEach(items, id: \.self) { item in | |
NavigationLink(item, destination: DetailView()) | |
} | |
}.onAppear { | |
print("onAppear list") | |
}.onDisappear { | |
print("onDisappear list") | |
} | |
} | |
} | |
} | |
struct DetailView: View { | |
var body: some View { | |
Text("detail") | |
.onAppear { | |
print("onAppear detail") | |
}.onDisappear { | |
print("onDisappear detail") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After starting the app (only list is visible):
onAppear list
After selecting an entry from the list:
After going back to list:
🤷♂️