Feature request: Add CaseIterable
implementation to generated enum from a kotlin sealed class that contains objects
#18
Replies: 6 comments
-
Hey @corrado4eyes, thanks for the idea. In Could you also share your usecase for |
Beta Was this translation helpful? Give feedback.
-
Hi @TadeasKriz I forked the repo and gave it a try by adding My use case is to be able to loop over a sealed class and when I put the value inside a switch statement I want it to be exhaustive. At the moment from kotlin I expose an To be honest at the moment I didn't put that much thought on Android because I could use reflekt or kotlin-reflect to get a list of the subclasses of a sealed class. Also on android the sealed class inside a |
Beta Was this translation helpful? Give feedback.
-
Hi! If I understand the problem correctly, we can add support for CaseIterable, but only in cases where all children of the sealed class are objects. Would that be enough for your use case? The problem with regular classes is that you can have multiple different instances for each of those classes (with different values), which makes it impossible to implement the |
Beta Was this translation helpful? Give feedback.
-
Hi @FilipDolnik, even in case you have only objects that won't be working. Also that doesn't fit my use case because some of those
For the following kotlin sealed class, this is the generate swift enum sealed class OnlyObjectsSealedClass {
object ObjectOne : OnlyObjectsSealedClass()
object ObjectTwo : OnlyObjectsSealedClass()
object ObjectThree : OnlyObjectsSealedClass()
} enum OnlyObjectsSealedClass {
public typealias __Kotlin = shared.OnlyObjectsSealedClass
@frozen
public enum __Sealed : Swift.Hashable, Swift.CaseIterable {
case objectOne(Skie.KotlinModule.OnlyObjectsSealedClass.ObjectOne.__Kotlin)
case objectThree(Skie.KotlinModule.OnlyObjectsSealedClass.ObjectThree.__Kotlin)
case objectTwo(Skie.KotlinModule.OnlyObjectsSealedClass.ObjectTwo.__Kotlin)
}
} Note that Edit: I see what you meant in your comment above. Yes, even though the generated enum for only objects still generates cases that expect a parameter, you only have one possible instance to pass there and not multiple. |
Beta Was this translation helpful? Give feedback.
-
Yeah, it's unfortunately not as easy as adding the Thanks for the idea; we will put it in the "possible new features" pile. |
Beta Was this translation helpful? Give feedback.
-
Okay @FilipDolnik thanks for the quick responses! I will rename the issue to reflect what we discussed. |
Beta Was this translation helpful? Give feedback.
-
When I try to loop over an enum using
Skie.KotlinModule.SealedClassEnumName.__Sealed.allCases
allCases
won't be found since the generated enum is not implementingCaseIterable
protocolBeta Was this translation helpful? Give feedback.
All reactions