icerockdev / moko-kswift

Swift-friendly api generator for Kotlin/Native frameworks
https://moko.icerock.dev
Apache License 2.0
348 stars 21 forks source link

Add extension field to Kotlin sealed class for conversion to Swift enum #82

Open Pschsch opened 1 year ago

Pschsch commented 1 year ago

Now we need directly use initializer of *Ks types to instantiate it. Their names could be so big, so to improve readability we could use this sort of construction to decrease usage of long type names. Example: Now:

class VeryBigNameOfViewModel {
   sealed class State {
       data class Success(val data : String, val someOtherData : Int) : State()
       object Loading : State()
   }
}

class Controller : UIViewController {
  ...
  private func observeState(_ state : VeryBigNameOfViewModel.State) {
      switch VeryBigNameOfViewModelStateKs(state) /*not pretty*/ { ...
  }
}

Wish:

class Controller : UIViewController {
  ...
  private func observeState(_ state : VeryBigNameOfViewModel.State) {
      switch state.ksEnum /*for example*/ { ...
  }
}

Seems that it's not so hard)