Skip to content

Instantly share code, notes, and snippets.

@maltebucksch
Created June 26, 2018 08:07
Show Gist options
  • Save maltebucksch/328c6379265a45d389a86e0c843a880c to your computer and use it in GitHub Desktop.
Save maltebucksch/328c6379265a45d389a86e0c843a880c to your computer and use it in GitHub Desktop.
Realm Sync Service: Upload + Delete
private static func upload(_ object: Syncable, isUpdated: Bool) {
let url: URL
let httpMethod: String
if isUpdated {
url = object.resourceURL.appendingPathComponent("/\(object.getId())")
httpMethod = "PUT"
} else {
url = object.resourceURL
httpMethod = "POST"
}
performRequest(method: httpMethod, url: url, data: object.encoded())
}
private static func deleteObject(withId id: String, ofType type: Syncable.Type) {
let url = type.resourceURL.appendingPathComponent("/\(id)")
performRequest(method: "DELETE", url: url)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment