And another question: what are the plans about Cod...
# multiplatform
n
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
Codable is a Swift only protocol and not visible from ObjC interop.
NSCoding
is the ObjC version of
Codable
.
n
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
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
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
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
@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
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
AFAIK, kotlinx.serialization works just fine even without ktor client.