I'm really loving the increased readability from n...
# touchlab-tools
j
I'm really loving the increased readability from not having as many typealiases in 0.6.0, so thanks for doing that! ❤️. One readability issue I still have though is storing the result of a sealed class -> swift enum in a field. eg
let 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:
Copy code
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.
f
These are interesting ideas, I’ll add them to our backlog. The current name is this convoluted to avoid unnecessary name collisions, but we can add a config option to also generate the typealias as you proposed.
j
cool, thanks! 😊
t
I'm curious about your usecase, why do you save the result of
onEnum(of:)
and not the instance itself?
j
I'm using it in SwiftUI so try to keep as much work as possible outside the body. My whole usecase is: • I have functions in the shared Kotlin code that fetch data and return an EitherError, State where State is a sealed class/interface. • There's an intermediate step where it gets turned into an iOSEitherError,State which has
:  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.
Eg: here's a pre-SKIE enum generated from a sealed class:
that conforms to this protocol:
And then the function to convert an iOSEither to a Result has two variations for handling when it's a sealed class/enum (2nd) or not (1st):
(
ks
and is the equivalent to
onEnum(of:)
and just a shortcut for the
init
defined above)
t
Interesting, thanks for the details!
👍 1