From c3b5d337c58d3e94f3c7137233111df43b26a096 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 31 Mar 2020 20:42:39 -0500 Subject: [PATCH] Change to use 0 and 1 for boolean. --- .../Account/CloudKit/CloudKitAccountDelegate.swift | 2 ++ .../Account/CloudKit/CloudKitAccountZone.swift | 12 ++++++++---- .../CloudKit/CloudKitAccountZoneDelegate.swift | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift index 8c8c2a7de..d0a1c0262 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountDelegate.swift @@ -55,6 +55,7 @@ final class CloudKitAccountDelegate: AccountDelegate { func receiveRemoteNotification(for account: Account, userInfo: [AnyHashable : Any], completion: @escaping () -> Void) { let group = DispatchGroup() + BatchUpdate.shared.start() zones.forEach { zone in group.enter() @@ -64,6 +65,7 @@ final class CloudKitAccountDelegate: AccountDelegate { } group.notify(queue: DispatchQueue.main) { + BatchUpdate.shared.end() completion() } } diff --git a/Frameworks/Account/CloudKit/CloudKitAccountZone.swift b/Frameworks/Account/CloudKit/CloudKitAccountZone.swift index 532577e64..4630a97cd 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountZone.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountZone.swift @@ -198,13 +198,17 @@ final class CloudKitAccountZone: CloudKitZone { } func findOrCreateAccount(completion: @escaping (Result) -> Void) { - let predicate = NSPredicate(format: "isAccount = \"true\"") + let predicate = NSPredicate(format: "isAccount = \"1\"") let ckQuery = CKQuery(recordType: CloudKitContainer.recordType, predicate: predicate) query(ckQuery) { result in switch result { case .success(let records): - completion(.success(records[0].externalID)) + if records.count > 0 { + completion(.success(records[0].externalID)) + } else { + self.createContainer(name: "Account", isAccount: true, completion: completion) + } case .failure: self.createContainer(name: "Account", isAccount: true, completion: completion) } @@ -256,14 +260,14 @@ private extension CloudKitAccountZone { func newContainerCKRecord(name: String) -> CKRecord { let record = CKRecord(recordType: CloudKitContainer.recordType, recordID: generateRecordID()) record[CloudKitContainer.Fields.name] = name - record[CloudKitContainer.Fields.isAccount] = "false" + record[CloudKitContainer.Fields.isAccount] = "0" return record } func createContainer(name: String, isAccount: Bool, completion: @escaping (Result) -> Void) { let record = CKRecord(recordType: CloudKitContainer.recordType, recordID: generateRecordID()) record[CloudKitContainer.Fields.name] = name - record[CloudKitContainer.Fields.isAccount] = isAccount ? "true" : "false" + record[CloudKitContainer.Fields.isAccount] = isAccount ? "1" : "0" save(record) { result in switch result { diff --git a/Frameworks/Account/CloudKit/CloudKitAccountZoneDelegate.swift b/Frameworks/Account/CloudKit/CloudKitAccountZoneDelegate.swift index ab721ed84..62e0a4a22 100644 --- a/Frameworks/Account/CloudKit/CloudKitAccountZoneDelegate.swift +++ b/Frameworks/Account/CloudKit/CloudKitAccountZoneDelegate.swift @@ -83,7 +83,7 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { guard let account = account, let name = record[CloudKitAccountZone.CloudKitContainer.Fields.name] as? String, let isAccount = record[CloudKitAccountZone.CloudKitContainer.Fields.isAccount] as? String, - isAccount != "true" else { return } + isAccount != "1" else { return } var folder = account.existingFolder(withExternalID: record.externalID) folder?.name = name