Unrealm
Unrealm copied to clipboard
How to update only some properties of record?
How can I update only some properties with keeping old other properties? Seems like Realm.create(_ : value: update) is not implemented. Thanks for this awesome repo.
Can you bring an example of what you want to achieve?
Not sure why @NortromInsanlyDev did not supply one but I'll give it a go.
struct myObject { var name: String var age: Int var favPlaces:[String] }
I just want to update the favPlaces array without having to supply the entire object.
Imagine:
var myObj = realm.objects(ofType: MyObject.self).last!
if you update only one property:
myObj.favPlaces = ["SF", "LA"]
and save it to the realm by
try! realm.write {
realm.add(myObj)
}
It will keep the old properties unchanged
@arturdev I think a better example is I have
struct Parent {
var name: String
var superPower: String
var children: [Child]
}
struct Child {
var name: String
var talent: String
var grandchildren: [Grandchild]
}
struct Grandchild {
var age: Int
}
Given these data structures, say from my server I fetched an updated list of all of my parents' names and superPowers but didn't want to fetch all of the children and grandchildren because there was no modifications made to those objects. I'd like to have a way to update top-level properties of an array of objects and ignore the relations for those objects. your suggestion is that I have to first fetch the parent objects individually and update each individual property which is not very optimal.