I’m trying to figure out the best way to handle some things in my widget. For example, I have a database that all of my widgets get their data from. Ideally I’d like to load and initialize my database once, then query the same database instance from each timeline provider. Is that possible?
So far I've tried approaching this in a couple of different ways:
So far I've tried approaching this in a couple of different ways:
I can’t seem to find any shared object in the widget extension. For example, in an app I can call UIApplication.shared from anywhere, or in a watchOS app there’s WKExtension.shared(). From there I can access my custom delegate, which is useful in certain situations. Does a WidgetKit extension have something like this that I'm missing?
I thought I might be able to create an instance of the database in the WidgetBundle and then pass it through to each timeline provider. But it seems that a Widget can’t have initialization parameters, so I don’t see how I could pass that object in.