CloudCore
CloudCore copied to clipboard
Can't form Range with upperBound < lowerBound
I often get crashes with this error:
Can't form Range with upperBound < lowerBound
it happens in ObjectToRecordConverter.swift
on line 73:
private func convertOperations(from objectSet: Set<NSManagedObject>, changeType: ManagedObjectChangeType) -> [ObjectToRecordOperation] {
var operations = [ObjectToRecordOperation]()
for object in objectSet {
// Ignore entities that doesn't have required service attributes
guard let serviceAttributeNames = object.entity.serviceAttributeNames else { continue }
do {
let recordWithSystemFields: CKRecord
if let restoredRecord = try object.restoreRecordWithSystemFields() {
switch changeType {
case .inserted:
// Create record with same ID but wihout token data (that record was accidently deleted from CloudKit perhaps, recordID exists in CoreData, but record doesn't exist in CloudKit
let recordID = restoredRecord.recordID
recordWithSystemFields = CKRecord(recordType: restoredRecord.recordType, recordID: recordID)
case .updated:
recordWithSystemFields = restoredRecord
}
} else {
recordWithSystemFields = try object.setRecordInformation()
}
var changedAttributes: [String]?
// Save changes keys only for updated object, for inserted objects full sync will be used
if case .updated = changeType { changedAttributes = Array(object.changedValues().keys) }
let convertOperation = ObjectToRecordOperation(record: recordWithSystemFields,
changedAttributes: changedAttributes,
serviceAttributeNames: serviceAttributeNames)
convertOperation.errorCompletionBlock = { [weak self] error in
self?.errorBlock?(error)
}
convertOperation.conversionCompletionBlock = { [weak self] record in
guard let me = self else { return }
let cloudDatabase = me.database(for: record.recordID, serviceAttributes: serviceAttributeNames)
let recordWithDB = RecordWithDatabase(record, cloudDatabase)
me.convertedRecords.append(recordWithDB) // <--- here Can't form Range with upperBound < lowerBound
}
operations.append(convertOperation)
} catch {
errorBlock?(error)
}
}
return operations
}
Update
This line seems to fail with different reasons. This time I got Fatal error: UnsafeMutablePointer.deinitialize with negative count
Any idea what it could be?
