Best practice for using a single EKEventStore instance across threads?

Hello,

Regarding EKEventStore, the WWDC session mentions that “you should only have one of these for your application.” In my app, I need to use the instance on both the main thread and a background thread, and I would like to share a single instance across them.

However, EKEventStore is a non-sendable type, so it cannot be shared across different isolation domains. I would like to know what the recommended best practice is for this situation. Also, do I need to protect the instance from data races by using a lock?

Thank you.

Assuming you're writing in Swift, you can wrap EKEventStore in an Actor. This makes sure that EKEventStore is only accessed from a single thread, while you can make async calls from any other thread without worrying about locks - the use of Actor takes care of that.

Best practice for using a single EKEventStore instance across threads?
 
 
Q