Search code examples
objective-cswiftenumsbridge

Obj-C to Swift Bridging issues: NS_ENUM -> enum


I'm using a Obj-C lib in Swift project with a bridging. All are OK except NS_ENUM with custom value:

Obj-C (original)

typedef NS_ENUM(NSInteger, HTTPStatusCode) {
//    Informational 1xx
    HTTPStatusCodeContinue = 100,
    HTTPStatusCodeSwitchingProtocols = 101,
    HTTPStatusCodeProcessing = 102,
    HTTPStatusCodeCheckpoint = 103,
    ...

Swift (with bridging)

enum HTTPStatusCode : Int {

    //    Informational 1xx
    case Continue
    case SwitchingProtocols
    case Processing
    case Checkpoint
    ...

How NS_ENUM implementation to the bridging can convert to Swift correctly?


Solution

  • I think what you posted here is an automatically generated Swift code, meaning that it omits implementation details.

    Good news is that it still works in the same way you'd expect:

    let x: HTTPStatusCode = .Continue
    println("Continue = \(x.rawValue)") 
    

    prints 100