Jon Bailey
02/06/2024, 5:29 PMlet state: Skie.ApplicationNew.ApplicationSummary.__Sealed = onEnum(of: getState())
(obv not needed there but if it's stored in a field on a struct or something then the type is needed).
It seems like this works on both sealed interfaces and classes and reads a fair bit nicer, as well as being easier to type/find in autocomplete:
extension ApplicationSummary {
typealias Sealed = Skie.ApplicationNew.ApplicationSummary.__Sealed
}
as you're just adding .Sealed
(or maybe Exhaustive/Enum or something) on to the end of the main type from the shared code.
Another thing that would also help readability would be if the generated swift enums conformed to a protocol with an init that does self = onEnum(of: sealed)
so that the conversion to the swift enum could be done in generic functions, reducing the need to call onEnum(of:) all over the codebase.Filip Dolník
02/06/2024, 5:41 PMJon Bailey
02/06/2024, 6:01 PMTadeas Kriz
02/06/2024, 6:43 PMonEnum(of:)
and not the instance itself?Jon Bailey
02/06/2024, 7:36 PM: Any
constraints on the generics so it not optional in Swift)
• Then in Swift I have a Result.init extension function that converts an iOSEither to a Swift Result.
• Previously the Swift enums I generated with KSP all conformed to a protocol so in the Result.init function I could also convert the Kotlin sealed class to it's Swift enum.Jon Bailey
02/06/2024, 7:37 PMJon Bailey
02/06/2024, 7:37 PMJon Bailey
02/06/2024, 7:39 PMJon Bailey
02/06/2024, 7:39 PMks
and is the equivalent to onEnum(of:)
and just a shortcut for the init
defined above)Tadeas Kriz
02/06/2024, 7:40 PM