Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Can't form Range with upperBound < lowerBound #26

Open
eRGoon opened this issue Mar 14, 2018 · 1 comment
Open

Can't form Range with upperBound < lowerBound #26

eRGoon opened this issue Mar 14, 2018 · 1 comment

Comments

@eRGoon
Copy link

eRGoon commented Mar 14, 2018

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
}
@eRGoon
Copy link
Author

eRGoon commented Mar 15, 2018

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?

bildschirmfoto 2018-03-15 um 08 59 42

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant