Created
July 16, 2021 11:21
-
-
Save cmelchior/c4e2fd356c54bfedd73e6c8b80f2d0e9 to your computer and use it in GitHub Desktop.
Realm Kotlin 0.40 Release Blog Post - Updating Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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