Ios 自动与服务器同步

Ios 自动与服务器同步,ios,swift,restkit,realm,Ios,Swift,Restkit,Realm,我正在使用带有一些api的realm,我希望在服务器上删除对象时,它会在应用程序上自动删除。 有了CoreData,就有了一个RestKit框架,realm也有类似的功能。我尝试了ObjectMapper和Alamofire,但没有成功 您需要自行处理对象删除。这可能如下所示: Alamofire.request(.DELETE, "http://localhost:3000/product/\(object.id).json") .response { request, re

我正在使用带有一些api的realm,我希望在服务器上删除对象时,它会在应用程序上自动删除。
有了CoreData,就有了一个RestKit框架,realm也有类似的功能。我尝试了ObjectMapper和Alamofire,但没有成功

您需要自行处理对象删除。这可能如下所示:

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)
             }
         }