A
A
Arman2016-06-23 09:06:09
Swift
Arman, 2016-06-23 09:06:09

How to work with enum in swift?

Good morning.
I'm just learning swift and so far I can't really understand how to work with enum.
Let's say you need to make Makes and Models of cars, this is just an example, I want to understand how to work with it. It turns out that we have the data in the form of a tree, it should not turn out "Mercedes Camry"

enum Toyota: String {
    case Camry = "Camry",
    Avensis = "Avensis",
    Corolla = "Corolla",
    Avalon = "Avalon"
}
enum Mercedes: String {
    case S_600 = "S 600",
    G_65_AMG = "G 65 AMG",
    C_63_AMG = "C 63 AMG"
}
enum Volkswagen: String {
    case Passat = "Passat",
    Golf = "Golf",
    Touareg = "Touareg",
    Polo = "Polo",
    Vento = "Vento",
    Jetta = "Jetta"
}
enum MM { //: ?
    case Toyota
    case Mercedes
    case Volkswagen
}

Have I assembled the enum correctly? Those. I need to store one type, which should contain the Model and Make of the car.
For me, it’s more customary to store this separately, i.e. the model (class Car) will have two properties mark and model, but I decided to learn how to work with enum.
Questions:
1. How to implement it correctly so that there is one data type
2. It should be in the form of a tree
3. The ability to somehow store this type in the database and, accordingly, then again come to this type
4. The ability to set if / switch is not only acceptable on Volkswagen. Passat, but also for all Volkswagen models, i.e. when the brand is important to us, but not the model
Or maybe this type is not suitable for this at all and we need to dig in the other direction?
Links to interesting articles are welcome, otherwise they tell the same thing.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semchenko, 2016-06-23
@0xcffaedfe

How is it written in the book?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question