I made iOS app and it was CoreData+CloudKit, but when I unchecked CloudKit, CoreData's data became Read Only.

Asked 2 years ago, Updated 2 years ago, 43 views

Simply uncheck CloudKit in Target Signing & Capabilities.
As soon as you launch the app, the following message appears on the console:

[error] fault—Store opened without NSPersistentHistoryTrackingKey but previously had been opened with NSPersistentHistoryTrackingKey-Forcing into Read Only mode

I heard that I should return the history tracking option to ON, but I don't know where to set it.
(I don't remember turning it off explicitly in the first place)
If anyone knows, please let me know.
Thank you for your cooperation.

swift xcode

2022-09-30 10:43

1 Answers

If you are reporting this phenomenon, it would be easier to answer questions about what your current project is like, such as target iOS version, Xcode version, and how you created the original project, in as much detail as possible.

Assume that "Core Data + CloudKit" did the following when creating the project:

New Project Screen

In this case, the code generated when creating the project itself is different from specifying Core Data only.

AppDelegate.swift

(Core Data + CloudKit, Excerpt)

lazy var persistentContainer:NSPersistentCloudKitContainer={
        /*
         The persistent container for the application.This implementation
         create and returns a container, having loaded the store for the
         application to it.This property is optional since there are legacy
         error conditions that could cause the creation of the store to fail.
        */
        let container = NSPersistentCloudKitContainer(name: "CoreDataCloudKitSample")
        container.loadPersistentStores(completionHandler:{(storeDescription, error)in
            iflet error=error as NSError?{
                // Replace this implementation with code to handle the error appropriate.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, through it may be used during development.
                 
                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disposals writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error\(error), \(error.userInfo)")
            }
        })
        return container
    }()

AppDelegate.swift

(Core Data only, excerpt)

lazy var persistentContainer:NSPersistentContainer={
        /*
         The persistent container for the application.This implementation
         create and returns a container, having loaded the store for the
         application to it.This property is optional since there are legacy
         error conditions that could cause the creation of the store to fail.
        */
        let container = NSPersistentContainer(name: "CoreDataSample")
        container.loadPersistentStores(completionHandler:{(storeDescription, error)in
            iflet error=error as NSError?{
                // Replace this implementation with code to handle the error appropriate.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, through it may be used during development.
                 
                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disposals writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error\(error), \(error.userInfo)")
            }
        })
        return container
    }()

Try creating your own Core Data + CloudKit and Core Data-only projects and correcting the differences to match the Core Data-only projects.


2022-09-30 10:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.