I am looking to create an entity on both platform....
# multiplatform
m
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
If it is for store data localy you can try to use sqldelight because i dont think that Realm is multiplatform.
m
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
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
Thank you a lot
k
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
@kpgalligan Thank you a lot!! I am going to dig into that.
k
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
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
“Do you think that sqldelight is production ready?” Very much so.
m
Yes thx a lot, I am going to try it!
👍 1
v
@kpgalligan does sqldelight supports encryption also ?