Dragisa Dragisic
Dragisa Dragisic

Reputation: 750

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

I have enum like this:

public enum TrackingValue {

    case constant(String)
    case customVariable(name: String)
    case defaultVariable(DefaultVariable)

    public enum DefaultVariable {
        case advertisingId
        case advertisingTrackingEnabled
        case appVersion
        case connectionType
        case interfaceOrientation
        case isFirstEventAfterAppUpdate
        case requestQueueSize
        case adClearId
    }
}

Does anyone have any best-practice suggestion on how to make something like this available in Objective-C?

Thanks

Upvotes: 0

Views: 2067

Answers (1)

Sergey Petruk
Sergey Petruk

Reputation: 781

You can use only Enums witch can be represented in objc:

  1. Enums without nested enums
  2. Enums without parameters
  3. Enums raw types should be integer

Therefore you can only create another enum, witch can be represented in objc and just add method to convert to it:

public enum TrackingValue {
  ...

  func toObjc() -> ObjcEnum {
     ...
  }
}

and create somewhere swift method to another side:

func convert(_ type: ObjcEnum) -> TrackingValue {
   ...
}

Upvotes: 1

Related Questions