Using enums for constants seems to be a simple and elegant solution. Is there a way I can achieve a nested string output using enums?
For example, consider I have the following piece of code:
enum Const {
enum Car {
static let Door = "Door"
static let Engine = "Engine"
}
}
Is there anyway that I can get "Car| Door" as an output for Const.Car.Door? or "Car| Engine" as output for Const.Car.Engine? and "Car" as output for Const.Car?. I have some analytics constants defined in my current project similar to namespace pattern. It has a LOT of nested tracking events and would really help if I can achieve what I just described above.
What I require:
Const.Car should give the output "Car"
Const.Car.Door should give the output "Car| Door"
Const.Car.Engine should give the output "Car| Engine"
I have no idea on how to achieve that.
EDIT:
This should be also be extendable,
For example,
Const.Car.Door.Handle should give the output "Car| Door| Handle"
Const.Plane should give the output "Plane"
Const.Plane.Flaps should give the output "Plane| Flaps"
Const.Carcannot be both a string and an enum (inConst.Car.Door)Const.Car == "Car"thenConst.Car.Dooris invalid.