I have
class ViewModel: ObservableObject {
@Published var vehicle: any Vehicle
}
then in the view
var body : some View {
if let truck = vm.vehicle as? Truck {
TextField("Name", text: $vm.truck.name) // how to write this so it compiles?
}
}
name is a property of Truck, but not Vehicle. What I'm trying to do, is if it's castable to a truck then show this textfield, otherwise don't show it.