Migrate default data from UserDefaults.standard to UserDefaults(suitName:)

75 views Asked by At

I am making an app with a widget which shares an accent color through UserDefaults.

Now through out the app I have used UserDefaults.standard, but after adding widgets it was necessary to create app groups, so I created app groups to share persistence data with the widget.

I am not able to share my defaults with the widget with obvious reason that UserDefaults.standard don't share data on app extensions (ie: Widget etc) for that we need to use UserDefaults(suitName: "appGroup").

Now we know that we migrate sqlite database for persistence to the app group url path from the old store.

Can we do it similarly for the UserDefaults.standard to UserDefaults(suitName:)? Because if I use UserDefaults(suitName) directly all the defaults are reset.

Please correct me if I am wrong or suggest a good practice.

0

There are 0 answers