Let's see the simple source code:
import SwiftUI
struct MyView: View {
@State var mapState: Int
init(inputMapState: Int)
{
mapState = inputMapState //Error: 'self' used before all stored properties are initialized
} //Error: Return from initializer without initializing all stored properties
var body: some View {
Text("Hello World!")
}
}
I need the init function here because I want to do some data loading here, but there is one problem, the @State
variable could not be initialize here! How could I do with that?
Maybe it's a very simple question, but I don't know how to do.
Thanks very much!