You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enum AnimationLengthAdvanced {
case short
case long
case custom(Double)
var duration: Double {
switch self {
case .short:
return 2
case .long:
return 5.0
case .custom(let duration):
return duration
}
}
}
Translates to:
sealed class AnimationLengthAdvanced {
object short : AnimationLengthAdvanced()
object long : AnimationLengthAdvanced()
data class custom(val v1: Double) : AnimationLengthAdvanced()
val duration: Double
get() {
when (this) {
short -> return 2
long -> return 5.0
custom -> return duration
}
}
}
But it should be:
sealed class AnimationLengthAdvanced {
object short : AnimationLengthAdvanced()
object long : AnimationLengthAdvanced()
data class custom(val v1: Double) : AnimationLengthAdvanced()
val duration: Double
get() {
when (this) {
short -> return 2
long -> return 5.0
is custom -> return duration
}
}
}
Note that despite we do not have type information for the enums, we can deduct it is a class when the case comes with tuple information.
The text was updated successfully, but these errors were encountered:
This Swift code:
Translates to:
But it should be:
Note that despite we do not have type information for the enums, we can deduct it is a class when the case comes with tuple information.
The text was updated successfully, but these errors were encountered: