兼容oc的枚举定义
22 May 2023
兼容OC的枚举定义
@objc
public enum XXEnumType: Int, RawRepresentable {
case a = 1
case b = 2
public typealias RawValue = String
public var rawValue: RawValue {
switch self {
case .a: return "A"
case .b: return "B"
}
}
public var intValue: Int {
switch self {
case .a: return 1
case .b: return 2
}
}
public init?(rawValue: Self.RawValue) {
switch rawValue {
case "A": self = .a
case "B": self = .b
default:
return nil
}
}
public init?(intValue: Int) {
switch intValue {
case 1: self = .a
case 2: self = .b
default:
return nil
}
}
}
#iOS
