Let’s say I have a constant with an Enum type. Based on the value of that constant, I want to restrict the Enum type of another constant.
Example: I have a vehicle. Depending on whether that vehicle is human-powered or motorized, I want to say what specific kind of vehicle I have.
enum VehicleType {
enum HumanPoweredVehicle {
case bicycle
case skateboard
case pogoStick
}
enum MotorizedVehicle {
case car
case truck
case motorcycle
}
case humanPowered
case motorized
}
struct Vehicle {
var vehicleType: VehicleType
var specificVehicle: // ??? what do I put here
}
var v: Vehicle
So if v.vehicleType = .humanPowered
I want v.specificVehicle
to be restricted to values from the VehicleType.HumanPoweredVehicle
enum. But if it’s .motorized
then I would want it to be a value from the VehicleType.MotorizedVehicle
enum.
How would I do that?