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

Maurice Jouvet

11/28/2019, 12:54 PM
I am looking to create an entity on both platform. Simple one User with an id and a name. I created an expect class User { var id: Long, var name: String } And on Android the actual is using RealmObject (which works fine) I wanted to use the same on iOS. But here I’m stuck. How can I achieve that? Can I use Realm directly with Kotlin for iOS or is it impossible?
m

mben

11/28/2019, 12:59 PM
If it is for store data localy you can try to use sqldelight because i dont think that Realm is multiplatform.
m

Maurice Jouvet

11/28/2019, 1:11 PM
Yes, it is not. But is it possible to use it? I mean if I want to use a specific platform lib, I have to use it directly in Xcode? I would like to have the maximum code reused, and I would like to avoid to duplicate my entities.
a

Artyom Degtyarev [JB]

11/28/2019, 1:13 PM
As I can see, Realm has an Objective-C framework(https://realm.io/docs/objc/latest/) that can be interop’ted. Please have a look at this manual(https://github.com/JetBrains/kotlin-native/blob/master/COCOAPODS.md), maybe this way would be appropriate for your case.
m

Maurice Jouvet

11/28/2019, 1:15 PM
Thank you a lot
k

kpgalligan

11/28/2019, 1:42 PM
Realm will be difficult to use. I haven’t used it in a while, but as I recall, they do a fair bit of instrumentation of classes, at least on the JVM. The easiest way to communicate to both sides would probably be by way of interfaces rather than expect/actual. If you want to do interop and expect/actual, you’ll need to run interop on the objc code you write for you models as well, just fyi.
In that case, there’s a good chance the objc and kotlin/jvm won’t match up 100%. I gave talks recently about using extension fun/val to help bridge platform code. That may be useful.
m

Maurice Jouvet

11/28/2019, 1:44 PM
@kpgalligan Thank you a lot!! I am going to dig into that.
k

kpgalligan

11/28/2019, 1:48 PM
As for realm as a choice, I wouldn’t say I’ve ever been a fan, but now that they’ve been purchased I get the distinct impression things have been slowing down. Those docs mention Kotlin for JVM, but mostly explaining how to handle workarounds.
I am quite partial to sqldelight, of course, so take my opinion with healthy skepticism. However, once you get going it’ll be much easier to use.
m

Maurice Jouvet

11/28/2019, 1:51 PM
Oh, ok. I am watching your talk right now. I tried Realm because I use it before on Android and I saw that on iOS it’s used as well. But I used to use Room on Android. Do you think that sqldelight is production ready? I mean, can I use it like I use Room (with Foreign key, Update/Delete cascade and so on?)
k

kpgalligan

11/28/2019, 1:51 PM
“Do you think that sqldelight is production ready?” Very much so.
m

Maurice Jouvet

11/28/2019, 1:51 PM
Yes thx a lot, I am going to try it!
👍 1
v

Venkat , Bangalore , India

02/06/2020, 10:42 AM
@kpgalligan does sqldelight supports encryption also ?
2 Views