How to make a Swift String enum available in Objective-C?

前端 未结 10 2127
情深已故
情深已故 2020-12-01 07:09

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,

10条回答
  •  伪装坚强ぢ
    2020-12-01 07:35

    Here's a solution that works.

    @objc public enum ConnectivityStatus: Int {
        case Wifi
        case Mobile
        case Ethernet
        case Off
    
        func name() -> String {
            switch self {
            case .Wifi: return "wifi"
            case .Mobile: return "mobile"
            case .Ethernet: return "ethernet"
            case .Off: return "off"
            }
        }
    }
    

提交回复
热议问题