Post

Replies

Boosts

Views

Activity

Store data separately for each instance of a widget
Is there any way for a widget to store data in a way that is separate from other instances of the same widget? If I save data to UserDefaults.standard, other widgets have access to the same data. I could force the user to configure the app manually, but I would rather prefer to give the widget a set of default parameters when it is added, based on the state of the parent app. These parameters must be saved somewhere, possibly in UserDefaults using a key unique to the widget instance. There seems to be an ID which is part of the WidgetInfo structure, but I can't find out how to read this.
1
2
1.2k
May ’21