Search code examples
ioscore-datacloudkit

share NSPersistentCloudKitContainer between app and extension


I have an embedded framework that defines my core data container on CloudKit with:

let container = NSPersistentCloudKitContainer(name: containerName, managedObjectModel: objectModel)

This embedded framework is used by the app to insert/read data in this coredata container.

I want to add an (intent) app extension that may act directly on this same coredata container.

How can I access this CloudKit container from the extension? Is there a way to do that? And also how to share the same object model file (.xcdatamodeld) between app and extension?


Solution

  • You need to use App Group, and I can provide you this example for starting point.

    Also if you are interested in how to pass data from Siri intent to your app, take a look at this question