Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate complex enums to Sealed classes #32

Closed
angelolloqui opened this issue Oct 27, 2017 · 1 comment
Closed

Translate complex enums to Sealed classes #32

angelolloqui opened this issue Oct 27, 2017 · 1 comment

Comments

@angelolloqui
Copy link
Owner

angelolloqui commented Oct 27, 2017

When an enum in Swift contains tuples must be transltated to Sealed classes, which is the closest in Kotlin.

Example:

Swift:

enum Barcode {
    case upc(Int, Int, Int, Int)
    case qrCode(named: String)
    case empty
}

Koltin:

sealed class Barcode {
   data class upc(val v1: Int, val v2: Int, val v3: Int, val v4: Int) : Barcode()
   data class qrCode(val named: String) : Barcode()
   object empty : Barcode()
}
@angelolloqui
Copy link
Owner Author

Declaration fixed, but the enum swift case should also remove tuple parameters. Example:

Swift:

switch enumValue {
case .resetPasswordSendEmail:
    return (category: "ResetPassword", name: "sendEmail", label: nil)
case .paymentSelectorOpen(_, let tenant, _, let option):
    return (category: "PaymentSelector", name: "open", label: "\(tenant.name) - \(option.duration)min")
}

Should be:

when (enumValue) {
    .resetPasswordSendEmail -> return (category: "ResetPassword", name: "sendEmail", label: null)
    .paymentSelectorOpen -> return (category: "PaymentSelector", name: "open", label: "${tenant.name} - ${option.duration}min")
}

angelolloqui added a commit that referenced this issue Nov 18, 2017
#32 Added support for enum to sealed classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant