Created
June 26, 2018 08:07
-
-
Save maltebucksch/328c6379265a45d389a86e0c843a880c to your computer and use it in GitHub Desktop.
Realm Sync Service: Upload + Delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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