Using realm with SiriKit



I added a SiriKit extension to my app so that users are able to update their task lists using Siri. Unfortunately, I’m unable to import RealmSwift inside a class I created where I post process the text extracted by Siri (because the intent extension is checked off in the class’ Target Membership list). I’ve looked online and a lot of examples make use of NSUserDefaults. I was wondering if there is a way to directly use Realm?

Thank you.


Can I share my database in App Groups to achieve what I want?

I found a post on SO that shows how to do just that:

To share Realms between apps in the same iOS app group, you’ll need to specify a common location for the Realm:

let fileURL = FileManager.default
    .containerURL(forSecurityApplicationGroupIdentifier: "")!
let config = Realm.Configuration(fileURL: fileURL)
let realm = try Realm(configuration: config)

It’s still not perfectly clear to me how I would be able to use realm without an import statement?

Thank you.


I dont know about SiriKit, but on apple watch you definitely can use realm.

You can find some info about it here:

[Hint: Its made by using App Groups, but take a note on]


Thank you, freeubi, that’s super helpful.

Do I need to specify all the classes managed by Realm in my AppDelegate? Does that mean all of the classes in my project?


All the realm models.
You can create one Realm configuration for the Sirikit/Watchkit (with just the models there) and one for the whole app without configuring the models. :slight_smile: Less hassle that way.


That makes sense. Thanks again :blush: