mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 12:27:32 +01:00
Make cloudKitDidModify an async/await function.
This commit is contained in:
parent
75b16d206d
commit
18e0c48bd8
@ -31,7 +31,8 @@ import CloudKitExtras
|
||||
self.articlesZone = articlesZone
|
||||
}
|
||||
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey]) async throws {
|
||||
|
||||
for deletedRecordKey in deleted {
|
||||
switch deletedRecordKey.recordType {
|
||||
case CloudKitAccountZone.CloudKitFeed.recordType:
|
||||
@ -53,8 +54,6 @@ import CloudKitExtras
|
||||
assertionFailure("Unknown record type: \(changedRecord.recordType)")
|
||||
}
|
||||
}
|
||||
|
||||
completion(.success(()))
|
||||
}
|
||||
|
||||
func addOrUpdateFeed(_ record: CKRecord) {
|
||||
|
@ -66,7 +66,7 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||
migrateChangeToken()
|
||||
}
|
||||
|
||||
func refreshArticles(completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
@MainActor func refreshArticles(completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
fetchChangesInZone() { result in
|
||||
switch result {
|
||||
case .success:
|
||||
|
@ -32,7 +32,21 @@ class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate {
|
||||
self.articlesZone = articlesZone
|
||||
}
|
||||
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey]) async throws {
|
||||
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
self.cloudKitDidModify(changed: changed, deleted: deleted) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume()
|
||||
case .failure(let error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
Task { @MainActor in
|
||||
do {
|
||||
|
@ -29,7 +29,7 @@ public enum CloudKitZoneError: LocalizedError {
|
||||
|
||||
public protocol CloudKitZoneDelegate: AnyObject {
|
||||
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result<Void, Error>) -> Void);
|
||||
func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey]) async throws
|
||||
}
|
||||
|
||||
public typealias CloudKitRecordKey = (recordType: CKRecord.RecordType, recordID: CKRecord.ID)
|
||||
@ -129,7 +129,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
}
|
||||
|
||||
func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: @escaping () -> Void) {
|
||||
@MainActor func receiveRemoteNotification(userInfo: [AnyHashable : Any], completion: @escaping () -> Void) {
|
||||
let note = CKRecordZoneNotification(fromRemoteNotificationDictionary: userInfo)
|
||||
guard note?.recordZoneID?.zoneName == zoneID.zoneName else {
|
||||
completion()
|
||||
@ -736,7 +736,7 @@ public extension CloudKitZone {
|
||||
}
|
||||
|
||||
/// Fetch all the changes in the CKZone since the last time we checked
|
||||
func fetchChangesInZone(completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
@MainActor func fetchChangesInZone(completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
var savedChangeToken = changeToken
|
||||
|
||||
@ -776,17 +776,14 @@ public extension CloudKitZone {
|
||||
|
||||
switch CloudKitZoneResult.resolve(error) {
|
||||
case .success:
|
||||
DispatchQueue.main.async {
|
||||
self.delegate?.cloudKitDidModify(changed: changedRecords, deleted: deletedRecordKeys) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.changeToken = savedChangeToken
|
||||
Task { @MainActor in
|
||||
do {
|
||||
try await self.delegate?.cloudKitDidModify(changed: changedRecords, deleted: deletedRecordKeys)
|
||||
completion(.success(()))
|
||||
case .failure(let error):
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
case .zoneNotFound:
|
||||
self.createZoneRecord() { result in
|
||||
switch result {
|
||||
|
Loading…
x
Reference in New Issue
Block a user