icerockdev / moko-kswift

Swift-friendly api generator for Kotlin/Native frameworks

Home Page:https://moko.icerock.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get Kotlin object from swift enum

cl3m opened this issue · comments

When object are created from Swift, there is no way to get the kotlin sealed object.

It would be great if the plugin generate the reverse operation toObject() :

public enum ActionKs {
  case test
  case test2(Action.Test2)

  public init(_ obj: Action) {
    if let obj = obj as? common.Action.Test2 {
      self = .test2(obj)
    } else if obj is common.Action.Test {
      self = .test
    } else {
      fatalError("ActionKs not syncronized with Action class")
    }
  }

  public func toObject() -> Action {
      switch self {
      case .test2(let obj):
          return obj
      case .test:
          return common.Action.Test()
      }
  }
}