Is it possible to write a data class in a Kotlin M...
# kotlin-native
j
Is it possible to write a data class in a Kotlin Multiplatform library that, when built for macOS, conforms to Equatable (or better yet, Identifiable) out of the box?
👀 3
s
Those are Swift only protocols and cannot be implemented in Kotlin or ObjectiveC.
l
I believe you can write a Swift extension for Kotlin's
Any?
and delegate to
equals
. Does it work for you @Julio Zynger?
😅 1
a
AFAIK for
Identifiable
you just need a field named
id
in your data class. Then you can simply add
Identifiable
Swift extension to the Kotlin data class.
Copy code
data class Data(val id: String)

extension Data : Identifiable {
}
I have a sample here.
👆 1
💯 1
343 Views