Thread
#multiplatform
    Nikita Khlebushkin

    Nikita Khlebushkin

    2 years ago
    And another question: what are the plans about Codable protocol (Swift specific) support? Will it be resolved at some point or should I look for workarounds? (If the latter is correct, are there any examples of how it can be addressed)?
    s

    Sam

    2 years ago
    Codable is a Swift only protocol and not visible from ObjC interop.
    NSCoding
    is the ObjC version of
    Codable
    .
    Nikita Khlebushkin

    Nikita Khlebushkin

    2 years ago
    My bad, sorry, I fixed the question. What I mean is is there a way to add Codable to the models when running from Swift?
    s

    Sam

    2 years ago
    How about in your Swift file?
    extension MyKotlinClass: Codable {}
    The compiler may not be able to generate the actual code, in which case you'll need to add the methods
    encode(to encoder: Encoder)
    and
    init(from decoder: Decoder)
    Nikita Khlebushkin

    Nikita Khlebushkin

    2 years ago
    If I understood you correctly, then it is something that I am trying to avoid: I am creating a shared library for iOS and Android, mostly consisting of models. Creating an extending class for each model is kind of killing all the joy
    d

    Dmitri Sh

    2 years ago
    nope it shouldn't kill all the joy. it is an extension on that, perfectly decoupled. but why would you want codable when kotlinx serializable works just fine in iOS if you're using ktor client
    Nikita Khlebushkin

    Nikita Khlebushkin

    2 years ago
    @Dmitri Sh The thing is that I don't use ktor (and tbh I don't want to change the project's api framework just because it's a dependency of kotlin-multiplatform)
    d

    Dmitri Sh

    2 years ago
    ok, that's fair. Still, I think a swift extension is perfectly fine. That's what I did for Identifiable (for my common models to be compatible with SwiftUI list requirement) and I don't feel this feels out of place.
    s

    svyatoslav.scherbina

    2 years ago
    AFAIK, kotlinx.serialization works just fine even without ktor client.