I was trying to bind an enum data type to a variable but its giving me error given bellow:
Cannot infer contextual base in reference to member
No exact matches in call to initializer
So my question is How can i declare an enum type Binded value in Swift UI?
I am using xcode of Version 13.4.1 (13F100)
My Codes are:
enum BackLightStatus {
case available
case notAvalable
case byDefault
}
import SwiftUI
struct KeyboardBackLightMainView: View {
@State var isBackLightAvailable:BackLightStatus = .byDefault
@State var backlightFlashing:Bool = false
func fireTimer() {
print("Timer fired!")
}
var body: some View {
NavigationView {
keyboardBackLightTestButton()
KeyboardBackLightResultView(isKeyboardBackLightAvailable: $isBackLightAvailable)
}
.onDisappear(){
backlightFlashing = false
Backlight.sharedBacklight.stopFlashing()
}
}
}
struct KeyboardBackLightResultView: View {
@Binding var isKeyboardBackLightAvailable : BackLightStatus = .byDefault // Error warning pops up here in xcode
var body: some View {
switch isKeyboardBackLightAvailable {
case .available:
Text("Keyboard BackLight is available and started to Flash. ")
.padding()
.font(.system(size: 16))
case .notAvalable:
Text("Keyboard BackLight is not available")
.padding()
.font(.system(size: 16))
.foregroundColor(.red)
case .byDefault:
EmptyView()
}
}
}
CodePudding user response:
The @Binding
wrapped property is just declared, w/o default, like
struct KeyboardBackLightResultView: View {
@Binding var isKeyboardBackLightAvailable : BackLightStatus // << here !!
// ...