Search code examples
iosswiftrestkitrealm

Automatic sync realm with server


Im using realm with some api and i want to reach the behavior when i delete object at server it should be automatically deleted on the app. With CoreData there is a RestKit framework that do the trick, does realm have something similar. I ve tried ObjectMapper and Alamofire with no success.


Solution

  • You will need to take care yourself of the object deletion. This might look like below:

    Alamofire.request(.DELETE, "http://localhost:3000/product/\(object.id).json")
             .response { request, response, data, error in
                 // TODO: Replace through appropriate error handling
                 precondition(error == nil, "An error occurred \(error!)")
                 let realm = try! Realm()
                 try! realm.write {
                     realm.delete(object)
                 }
             }