sealed class Status<T : Any> {
data class Success<T : Any>(val data: T) : Status<T>()
data class Failure<T : Any>(val exception: Exception) : Status<T>()
}
SealedToSwiftEnumFeature converts this to:
public enum StatusKs<T : Any> {
case success(StatusSuccess<T>)
case failure(StatusFailure<T>)
public init(_ obj: Status<T>) {
if let obj = obj as? shared.StatusSuccess<T> {
self = .success(obj)
} else if let obj = obj as? shared.StatusFailure<T> {
self = .failure(obj)
} else {
fatalError("StatusKs not syncronized with Status class")
}
}
}
However, as Any allows structs etc the code won't compile.
Instead, converting Any to AnyObject fixes the above compilation issue.
The Kotlin conversion of Status is as follows:
open class Status<T> : KotlinBase where T : AnyObject {
public init()
}
public class StatusFailure<T> : Status<T> where T : AnyObject {
public init(exception: KotlinException)
open func component1() -> KotlinException
open func doCopy(exception: KotlinException) -> StatusFailure<T>
open func isEqual(_ other: Any?) -> Bool
open func hash() -> UInt
open func description() -> String
open var exception: KotlinException { get }
}
public class StatusSuccess<T> : Status<T> where T : AnyObject {
public init(data: T)
open func component1() -> T
open func doCopy(data: T) -> StatusSuccess<T>
open func isEqual(_ other: Any?) -> Bool
open func hash() -> UInt
open func description() -> String
open var data: T { get }
}
Consider the following sealed class.
SealedToSwiftEnumFeature
converts this to:However, as
Any
allows structs etc the code won't compile.Instead, converting
Any
toAnyObject
fixes the above compilation issue.The Kotlin conversion of Status is as follows: