Following example has a very simple class with couple properties of string and enum types.
But somehow Picker does not change value.
Any ideas what am I doing wrong?
import SwiftUI
enum AccountType: String, Identifiable, CaseIterable {
var id: AccountType { self }
case Bank = "Bank Account"
case Cash = "Cash in a wallet"
}
class Account {
var name: String = ""
var type: AccountType = .Cash
}
struct ContentView: View {
@State var newAccount: Account = Account()
var body: some View {
VStack {
Picker("Type", selection: $newAccount.type) {
ForEach(AccountType.allCases) { (type: AccountType) in
Text(type.rawValue).tag(type)
}
}
}
.padding()
}
}
#Preview {
ContentView()
}