swift enum from raw value code example
Example 1: enum from raw value swift
enum TestEnum: String {
case Name = "Name"
case Gender = "Gender"
case Birth = "Birth Day"
}
let name = TestEnum(rawValue: "Name")! //Name
let gender = TestEnum(rawValue: "Gender")! //Gender
let birth = TestEnum(rawValue: "Birth Day")! //Birth
Example 2: enum raw value swift
enum numbers: Int {
case one = 1, two, three, four
}
let num = numbers.one
print(num.rawValue) // Output: 1