Coredata in ios keyboard extension

Viewed 543

I read below github page and used the code for sharing coredata between my ios Keyboard Extension and the app.

https://github.com/maximbilan/iOS-Shared-CoreData-Storage-for-App-Groups

The code is working right on the simulator but it is not working but addPersistentStore not working on real device:

lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
    // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
    // Create the coordinator and store
    var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)

    let directory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier:"group.testKeyboard.asanpardakht.ir")!

    let url = directory.appendingPathComponent("AsanPardakhtSharedData.sqlite")

    do {
        try coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
    } catch var error as NSError {
        coordinator = nil
        NSLog("Unresolved error \(error), \(error.userInfo)")
        abort()
    } catch {
        fatalError()
    }
    print("\(String(describing: coordinator?.persistentStores))")
    return coordinator
}()

I get below errors:

NSError domain: "NSCocoaErrorDomain" - code: 512

"reason" : "Failed to create file; code = 1"

I tried setting RequestOpenAccess to YES in my info.plist file but it is not still working. Does someone has any idead about the problem?

1 Answers
Related