I have one child class which contains the username
variable. I wanna access it from the parent class. But the variable does not appear when I type. And if I forcefully type Add_new_presets.username
, then it throws the following error.
Error: Instance member 'username' cannot be used on type 'Add_new_presets'; did you mean to use a value of this type instead?
Child class
import SwiftUI
struct Add_new_presets: View {
@State var username: String = ""
@FocusState var emailFieldIsFocused :Bool = false
var body: some View {
TextField(
"User name (email address)",
text: $username
)
.focused($emailFieldIsFocused)
.onSubmit {
//validate(name: username)
}
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.border(.secondary)
}
}
Parent class
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Add_new_presets()
Text( Add_new_presets.username)
.foregroundColor(Add_new_presets.emailFieldIsFocused ? .red : .blue)
}
}
}