Change to use 0 and 1 for boolean.
This commit is contained in:
parent
3f82a28d21
commit
c3b5d337c5
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,13 +198,17 @@ final class CloudKitAccountZone: CloudKitZone {
|
|||
}
|
||||
|
||||
func findOrCreateAccount(completion: @escaping (Result<String, Error>) -> 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<String, Error>) -> 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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue