Removing NSPersistentHistoryTrackingKey causes error.

So when I turn off NSPersistentHistoryTrackingKey I get this error then the App Crashes:


error: Store opened without NSPersistentHistoryTrackingKey but previously had been opened with NSPersistentHistoryTrackingKey - Forcing into Read Only mode store at ...


CoreData: error: Store opened without NSPersistentHistoryTrackingKey but previously had been opened with NSPersistentHistoryTrackingKey - Forcing into Read Only mode store at...


error: (8) attempt to write a readonly database

CoreData: error: (8) attempt to write a readonly database


File is in Read Only mode due to Persistent History being detected but NSPersistentHistoryTrackingKey was not included


How do I turn it off without having this happen?


Ray

I've got the same issue. Were you able to resolve this?


- David

I believe I have my code working again.

For the record I had edited the Options... and removed two relating to iCloud. I had to put those changes back in again.


            options = @{NSMigratePersistentStoresAutomaticallyOption: @YES,                    // Key to automatically attempt to migrate versioned stores
                        NSInferMappingModelAutomaticallyOption: @YES,                          // Key to attempt to create the mapping model automatically
                        NSPersistentStoreUbiquitousContentNameKey: @"my_DataStore",  // Option to specify that a persistent store has a given name in ubiquity.
                        NSPersistentStoreUbiquitousContentURLKey: icloudURLForLogs,            // Option to specify the log path to use for ubiquitous content logs.
                        NSPersistentHistoryTrackingKey: @YES
                        };

- David

I have the same problem. Have you find any answer for this?

Example with NSPersistentHistoryTrackingKey:

    static let containerCloud: NSPersistentCloudKitContainer = {
        let description = NSPersistentStoreDescription()
            description.url = SELF.storeURL
            description.configuration = "CloudKit"
            description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
            description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
            description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.jsblocker")
        let container = NSPersistentCloudKitContainer(name: "Model")
        container.persistentStoreDescriptions = [description]
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("LoadPersistentStores() error \(error), \(error.userInfo)")
            } else {
                #if DEBUG
                    print("DB container = CloudKit")
                #endif
            }
        })
        return container
    }()
Removing NSPersistentHistoryTrackingKey causes error.
 
 
Q