https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

Nikita Khlebushkin

11/07/2019, 4:08 PM
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

11/07/2019, 4:28 PM
Codable is a Swift only protocol and not visible from ObjC interop.
NSCoding
is the ObjC version of
Codable
.
n

Nikita Khlebushkin

11/07/2019, 7:17 PM
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

11/07/2019, 7:33 PM
How about in your Swift file?
Copy code
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)
n

Nikita Khlebushkin

11/07/2019, 8:11 PM
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

11/08/2019, 1:22 AM
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
n

Nikita Khlebushkin

11/08/2019, 8:33 AM
@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

11/09/2019, 5:19 AM
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

11/11/2019, 9:11 AM
AFAIK, kotlinx.serialization works just fine even without ktor client.
10 Views