How to use Parcelable in KMP?
Is Parcelable more complex to implement?
No, beacause now you can use the kotlin-parcelize plugin which generates the code automatically for you. The only thing you need to do is to add an annotation on top of your data class @Parcelize and extend Parcelable.
Lets implement Parcelize in KMP
Go to shared > build.gradle.kts > add plugin kotlin-parcelize
const val parcelize = "kotlin-parcelize"
plugins {
id(parcelize)
}
Go to shared > commonMain > NewzPlatformParcelable
Use expect-actual mechanism to define the expect Parcelable Inteface and Parcelize annotation class
Go to shared > androidMain > implement the actual Parcelable and Parcelize
In Android Platform we already have Parcelable and Parcelize so we just use the typealias to create a reference link between the expected class and the actual class itself.
Go to shared >…