In my app the user can select multiple contacts in a collectionview. when he selects the property "isSelected" will me set to true and the collectionview refreshes the selected cell. Here I can recognize a small delay between selection and the highlighting of the cell. But in the next step I create a group with the selected contacts and in the end I set the property "isSelected" to false. This takes an non acceptable amount of time for 50 objects (5 seconds) and needs to be tuned.
Here is my code to unselect all the selected contacts:
for contact in self.selectedContacts {
try! self.realm.write{
contact.isSelected = false;
self.realm.add(contact, update: true)
}
}
Is it possible to perform a batch-update at once?
Try putting the for loop inside the write block:
try! self.realm.write {
for contact in self.selectedContacts {
contact.isSelected = false;
self.realm.add(contact, update: true)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With