我試圖從原材料價值得到枚舉類型:如何從Swift的原始值中枚舉enum?
enum TestEnum: String {
case Name
case Gender
case Birth
var rawValue: String {
switch self {
case .Name: return "Name"
case .Gender: return "Gender"
case .Birth: return "Birth Day"
}
}
}
let name = TestEnum(rawValue: "Name") //Name
let gender = TestEnum(rawValue: "Gender") //Gender
但似乎rawValue
不字符串用空格工作:
let birth = TestEnum(rawValue: "Birth Day") //nil
任何建議如何得到它?
請看看這個:[http://stackoverflow.com/a/38390421/3024579](http://stackoverflow.com/a/38390421/3024579) – Alok