imagine that your Items
object has an id property and you want to delete old values not included in the new set, or you can delete everything just
let result = realm.objects(Items.self) realm.delete(result)
and then again add all the elements to the area, or you can also request every element not included in the new set
let items = [Items]() // fill in your items values // then just grab the ids of the items with let ids = items.map { $0.id } // query all objects where the id in not included let objectsToDelete = realm.objects(Items.self).filter("NOT id IN %@", ids) // and then just remove the set with realm.delete(objectsToDelete)
source share