I have this enum with String
values, which will be used to tell an API method that logs to a server what kind of serverity a message has. I\'m using Swift 1.2,
I think @Remi 's answer crashes in some situations as I had this:
My error's screesshot. so I post my edition for @Remi 's answer:
@objc public enum LogSeverity: Int, RawRepresentable {
case debug
case info
case warn
case error
public typealias RawValue = String
public var rawValue: RawValue {
switch self {
case .debug:
return "DEBUG"
case .info:
return "INFO"
case .warn:
return "WARN"
case .error:
return "ERROR"
}
}
public init?(rawValue: RawValue) {
switch rawValue {
case "DEBUG":
self = .debug
case "INFO":
self = .info
case "WARN":
self = .warn
case "ERROR":
self = .error
default:
return nil
}
}
}