Skip to content

Instantly share code, notes, and snippets.

@cmelchior
Created July 16, 2021 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmelchior/c4e2fd356c54bfedd73e6c8b80f2d0e9 to your computer and use it in GitHub Desktop.
Save cmelchior/c4e2fd356c54bfedd73e6c8b80f2d0e9 to your computer and use it in GitHub Desktop.
Realm Kotlin 0.40 Release Blog Post - Updating Data
CoroutineScope(Dispatchers.Main).launch {
// Create initial object
val jane = realm.write {
copyToRealm(Person("Jane"))
}
realm.write {
// Find latest version and update it
// Note, this always involves a null-check
// as another thread might have deleted the
// object.
// This also works on objects without
// primary keys.
findLatest(jane)?.apply {
name = "Jane Doe"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment