From ee466170c81152479ba7d35bc0e5ba3b0930c93a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 19 Apr 2024 22:17:02 -0700 Subject: [PATCH] Fix concurrency warnings. --- .../CloudKit/CloudKitAccountZoneDelegate.swift | 8 +++++--- .../CloudKit/CloudKitArticlesZoneDelegate.swift | 16 +--------------- .../Sources/CloudKitExtras/CloudKitZone.swift | 9 ++------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift index 293d695c2..1dec33a45 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift @@ -31,8 +31,8 @@ import CloudKitExtras self.articlesZone = articlesZone } - func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey]) async throws { - + func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result) -> Void) { + for deletedRecordKey in deleted { switch deletedRecordKey.recordType { case CloudKitAccountZone.CloudKitFeed.recordType: @@ -43,7 +43,7 @@ import CloudKitExtras assertionFailure("Unknown record type: \(deletedRecordKey.recordType)") } } - + for changedRecord in changed { switch changedRecord.recordType { case CloudKitAccountZone.CloudKitFeed.recordType: @@ -54,6 +54,8 @@ import CloudKitExtras assertionFailure("Unknown record type: \(changedRecord.recordType)") } } + + completion(.success()) } func addOrUpdateFeed(_ record: CKRecord) { diff --git a/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift index c93139442..02d3befc1 100644 --- a/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift @@ -32,21 +32,7 @@ class CloudKitArticlesZoneDelegate: CloudKitZoneDelegate { self.articlesZone = articlesZone } - 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) { + func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result) -> Void) { Task { @MainActor in do { diff --git a/CloudKitExtras/Sources/CloudKitExtras/CloudKitZone.swift b/CloudKitExtras/Sources/CloudKitExtras/CloudKitZone.swift index 88e9aa87d..3a2329a13 100644 --- a/CloudKitExtras/Sources/CloudKitExtras/CloudKitZone.swift +++ b/CloudKitExtras/Sources/CloudKitExtras/CloudKitZone.swift @@ -29,7 +29,7 @@ public enum CloudKitZoneError: LocalizedError { public protocol CloudKitZoneDelegate: AnyObject { - func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey]) async throws + func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result) -> Void) } public typealias CloudKitRecordKey = (recordType: CKRecord.RecordType, recordID: CKRecord.ID) @@ -1046,12 +1046,7 @@ public protocol CloudKitZone: AnyObject { switch result { case .success: - do { - try await self.delegate?.cloudKitDidModify(changed: changedRecords, deleted: deletedRecordKeys) - completion(.success(())) - } catch { - completion(.failure(error)) - } + self.delegate?.cloudKitDidModify(changed: changedRecords, deleted: deletedRecordKeys, completion: completion) case .failure(let error):