I have an enum
:
public enum PersonType:String {
case Cool = "cool"
case Nice = "rude"
case SoLazy = "so-lazy"
public var description: String {
switch self {
case .Cool:
return "Cool person"
case .Nice:
return "Nice person"
case .SoLazy:
return "its so lazy person"
}
}
public var typeImage: String {
switch self {
case .Cool:
return "cool.png"
case .Nice:
return "img_nice.png"
case .Solazy:
return "lazy.png"
}
}
}
The problem I don't know all the person type keys so I need to handle a default case of type person and to give it the description will be it's key like "so-lazy" and a default image.
let's say I get this result from the web service:
[
{
name: "john",
key: "cool"
},
{
name: "paul",
key: "funny"
}
]
I need to have a a default case to handle the key "funny"
here is how I init my enum while parsing and creating person object:
if let personType = PersonType(rawValue:personTypeKey ?? "") {
self.personType = personType
}
I want an else
or a better approach to handle the case of unknown keys in my enum, and give them the key as description and a default image.