Using realm with SiriKit


#1

Hello,

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.


#2

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: "group.io.realm.app_group")!
    .appendingPathComponent("default.realm")
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.


#3

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

You can find some info about it here: https://academy.realm.io/posts/tutorial-sharing-data-between-watchkit-and-your-app/

[Hint: Its made by using App Groups, but take a note on https://realm.io/docs/swift/latest#operating-with-low-memory-constraints]


#4

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?


#5

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.


#6

That makes sense. Thanks again :blush: