Is there a magic function to update all objects at once?
Equivalent in SQL would be something like UPDATE mytable SET active = 0
Or do I have to make a query first, then loop though it, updating properties for each object? My DB currently have >1700 objects and I didn't want to burden the app with such loops.
If this question has been asked previously, I apologise.
We actually have an optimized way of doing this -- [[MyObject allObjects] setValue:@NO forKeyPath:@"active"] -- could you give that a whirl?
We might want to add this to the documentation @segiddins
Yes, stating in the docs that we support collection KVC would be awesome.
It is documented at https://realm.io/docs/objc/latest/api/Protocols/RLMCollection.html
@staticdreams I've created #2288 to track adding this to our docs guide at https://realm.io/docs/objc/latest.
Thanks for the response.
I'm guessing in Swift this corresponds to this method https://realm.io/docs/swift/latest/api/Classes/List.html#/s:FC10RealmSwift4List8setValueU__FGS0_Q__FTGSqPSs9AnyObject__6forKeySS_T_ ?
But when I try to do something like this MyObject.setValue(0, forKey: "active") it compiles, but at runtime I'm getting a crash: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: ... setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key active.'
In my model I do have this property declared: dynamic var active: Int = 1
Am I missing something?
UPDATE: Nevermind. Found my problem. Works as expected. Thanks a lot :)
Most helpful comment
We actually have an optimized way of doing this --
[[MyObject allObjects] setValue:@NO forKeyPath:@"active"]-- could you give that a whirl?