I map my objects with ObjectMapper, that are delivered by Alamofire and persist them in Realm.
Everthing is working fine. But how can I delete objects, that exist in Realm but have been deleted in my webservice?
Update: Based on the answer below I currently ended with this code:
if let overviewItemsArray = response.result.value{
do{
try self.realm.write{
self.realm.delete(self.realm.objects(OverviewItem))
self.realm.add(overviewItemsArray, update: true)
}
}
catch let err as NSError {
logger.error("Error with realm: \(err.localizedDescription)")
}
overviewItemsAsList.removeAll()
overviewItemsAsList.appendContentsOf(self.realm.objects(OverviewItem)
.sorted("sortOrder", ascending: true))
successHandler(overviewItemsAsList)
}
Perhaps somebody has further input how to improve this. I have 10 objects of this type. But on other objects I get 1500 items.