Created
August 20, 2016 20:14
-
-
Save kwylez/0f2fab080ef79eb329705fe7fd480264 to your computer and use it in GitHub Desktop.
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
import Foundation | |
import CloudKit | |
public enum CloudKitError: Error { | |
case general(String) | |
} | |
public enum CloudKitResult<T, ResultError: Error> { | |
case success(T) | |
case failure(ResultError) | |
} | |
public typealias CloudKitFetchClosure<T> = (_ result: CloudKitResult<T, CloudKitError>) -> Void | |
public final class CloudKitController { | |
public typealias T = CKRecord | |
public func save(_ record: CKRecord, callback: CloudKitFetchClosure<T>) -> Void { | |
self.publicDB.save(record, completionHandler: {updatedRecord, error in | |
if let _: Error = error { | |
DispatchQueue.main.async(execute: { | |
callback(.failure(.general("Something went wrong"))) | |
}) | |
} else { | |
DispatchQueue.main.async(execute: { | |
callback(.success(updatedRecord)) | |
}) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment