Skip to content

Instantly share code, notes, and snippets.

@cmelchior
Created July 16, 2021 11:20
Show Gist options
  • Save cmelchior/a5739f4205d0b964ab508c3e8a9e247b to your computer and use it in GitHub Desktop.
Save cmelchior/a5739f4205d0b964ab508c3e8a9e247b to your computer and use it in GitHub Desktop.
Realm Kotlin 0.40 Release Blog Post - Suspendable Write
CoroutineScope(Dispatchers.Main).launch {
// Write automatically happens on a background dispatcher
val jane = realm.write {
val unmanaged = Person("Jane")
// Add unmanaged objects
copyToRealm(unmanaged)
}
// Objects returned from writes are automatically frozen
jane.isFrozen() // == true
// Access any property.
// All properties are still lazy-loaded.
jane.name // == "Jane"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment