I'm not even sure how to frame a sensible question...
# multiplatform
m
I'm not even sure how to frame a sensible question about Parcelize, KMM, and iOS. In essence I have a fundamental class marked as parcelable because I can have some of my basic data correctly packaged by my server, by the magic of KTor (and, to be fair, others) decoded completely and can then display it using that same structure in my Android app. KMM has an implementation of Parcelize, but what do I do for iOS??? I know I don't need data to be parcelable for iOS, but, as a basic data structure, I have it declared as expecting in commonMain and an actual declaration in adroidMain, and now iosMain is complaining it has no actual declaration. I'm beginning to suspect I shouldn't have that data put straight into a parcelable/parcelizable object, which means I've got extra overhead somewhere creating a new object from it, at least in my Android executable, but if that's the case, why does KMM go out of its way to provide a parcelizable construct?
r
You can just have a useless interface on iOS as implementation of your `expect`:
Copy code
actual interface Parcelable
If you’re talking about the
Parcelize
annotation,
expect annotation
can be optional:
Copy code
@OptionalExpectation
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
expect annotation class Parcelize()
d
Why do you have the fundamental class in common?
m
Because that's what I'm shipping out from my server
d
Ah, so you're sharing code between Android and server but you don't want that code in iOS?
m
@Gael, yes, that's what I've got (with an extra line, "@OptIn(ExperimentalMultiplatform::class)", for "expect", but what about "actual"? In androidMain I've got
Copy code
import kotlinx.parcelize.Parcelize
actual typealias Parcelize = Parcelize
but XCode complains about both those lines
@Dominaezzz, not code, they're just straight data classes, so yes, I do want that data on both platforms
k
Essenty has parcelize support for KMP
m
@kenkyee, looks great, and it's a big library to solve one problem... but wait, it doesn't solve it (mine at least). It says it doesn't include anything for the iOS side yet 😞 I'm also a bit concerned at including (even more) pre-release code (it says it's at version 0.1.3 😕 )
k
There's a PoC. You'll find that a lot of KMP libs are pre 1.0. welcome to the bleeding edge 😂
m
🙂 😞 Thanx Just looking at the PoC, ta.
I'm wondering, don't I just need something to keep the compiler happy while actually (hahaha... pun noted) doing nothing at all?
a
r
@MarkRS you don’t need anything in the ios part if you have
@OptionalExpectation
in the common part. Did you miss that line?
a
Also if you DO want to do it manually without a adding a dependency, here’s how I did it: https://ankushg.com/posts/multiplatform-parcelize/
m
Thanks for that @ribesg, somehow I hadn't connected those dots. XCode complains, but maybe it's not important. I'll try again. It's odd (is it?) that AS is fine with "import android.os.parcelable" in iosMain but refuses to recognise "import kotlinx.parcelize.Parcelize". Thanks for that @ankushg, that's really helpful. Incidentally you have the android-extensions plugin in that article, which is now gone. I found a some help for that, https://stackoverflow.com/questions/64925126/how-to-use-parcelize-now-that-kotlin-android-extensions-is-being-deprecated
👍 1