Plugin Using Core Data

I’m working on a custom plugin and I’m running into issues with iOS’s Core Data. The intention is to have the plugin write to Core Data so that an app extension I’m writing can read from Core Data. The problem I’m currently facing is that I don’t seem to find the ManagedObjectContext necessary to create the instance of a new Core Data object. Is it possible to access Core Data from a Capacitor Plugin? I can’t seem to find an example of anybody successfully doing it.

Here is the Ionic Info for the main app

These are the dependencies from the package.json for the plugin

“devDependencies”: {
@capacitor/android”: “^4.0.0”,
@capacitor/core”: “^4.0.0”,
@capacitor/docgen”: “^0.0.18”,
@capacitor/ios”: “^4.0.0”,
@ionic/eslint-config”: “^0.3.0”,
@ionic/prettier-config”: “^1.0.1”,
@ionic/swiftlint-config”: “^1.1.2”,
“eslint”: “^7.11.0”,
“prettier”: “~2.3.0”,
“prettier-plugin-java”: “~1.0.2”,
“rimraf”: “^3.0.2”,
“rollup”: “^2.32.0”,
“swiftlint”: “^1.0.1”,
“typescript”: “~4.1.5”
“peerDependencies”: {
@capacitor/core”: “^4.0.0”

Yes, you need to look at core data swift docs to understand it first.

Do you have an example of doing it? I’ve worked with CoreData before on the native side but never via a plugin. I can’t find a way to get the managed object context in the plugin code.

Capacitor has docs on how to create plugins, you should start reading there first. Creating Capacitor Plugins | Capacitor Documentation

I have read those. I’m asking specifically about how to get the managed context required for Core Data.