I'm trying to run a function when the app finish loading up, like viewDidLoad
, but I'm using SwiftUI now and I have no viewDidLoad
. How can I do this now?
var body: some View {
NavigationView {
Form {
Section {
self.exampleFunction()
Text(" ...... ")
}
}
}
}
I want to take some information from that function and present it in the text. But the way I'm doing it is wrong. It's not building.
You can use .onAppear { ... }
to execute arbitrary code when a view appears:
var body: some View {
NavigationView {
Form {
Section {
Text(" ...... ")
}.onAppear { self.exampleFunction() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With