How can I use an associated enum as a @State
variable in an if
statement in SwiftUI?
struct ProfileView: View {
@State private var choice = Choice.simple
private enum Choice {
case simple
case associated(Int)
}
var body: some View {
if choice == .simple {
Text("Simple")
}
}
}
The compiler reports this error:
Protocol 'Equatable' requires that 'ProfileView.Choice' conform to 'Equatable'
Here is fixed variant. Tested with Xcode 11.4.