iOS today extension with core data iOS today extension with core data xcode xcode

iOS today extension with core data


You should subclass NSPersistentCloudKitContainer like below, returning the App Group URL for defaultDirectoryURL(). Then in your CoreDataStack, use let container = GroupedPersistentCloudKitContainer(name: "SchoolCompanion"). Also remove, your call to addToAppGroup(...). You will need to instantiate the GroupedPersistentCloudKitContainer in both the App and the Extension, you will also need to make sure the GroupedPersistentCloudKitContainer is linked to both Targets.

class GroupedPersistentCloudKitContainer: NSPersistentCloudKitContainer {    enum URLStrings: String {        case group = "group.com.yourCompany.yourApp"    }    override class func defaultDirectoryURL() -> URL {        let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: URLStrings.group.rawValue)        if !FileManager.default.fileExists(atPath: url!.path) {            try? FileManager.default.createDirectory(at: url!, withIntermediateDirectories: true, attributes: nil)        }        return url!    }    ...}


The url for your app group is here:

let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "SchoolCompanion)

The sqlite-file is there. You don't need Cloud container.