There are a couple of typo’s in the code .objects(ofType: Parent.self)
should be .objects(Parent.self)
for example, but other than that it’s works as is. note this : Results<Child>
is not needed
In general the only task that must be within a write is when a managed object is modified so this is the only line that does that
parent.hasFlaggedChildren...
Technically you could encapsulate just that line within a write
try! realm.write {
parent.hasFlaggedChildren
}
But that leads to the next question; do you have any other code attempting to modify those objects after the query (the read?)
Results objects reflect the current state of those objects - if they are modified elsewhere it will be reflected here so that could be a factor.