Quick Follow Up
This is a quick follow up to the previous post regarding app groups. After verifying how it works, I went ahead and looked at how I can migrate my current settings from the standard defaults to the app group container. Here is how it went down…
First, I over-complicated things, as usual. I thought I could use a cascading similar to the one we saw in the UIFont post. Basically, I would have to wrap the
NSUserDefault with a subclass, and on every access to the defaults, I would check if that key is migrated or not, then migrate it from the standard defaults if it isn’t.
Then, I found an interesting method on
addSuiteNamed:. It seems that I can somehow compose the two defaults without worrying much about where the setting was actually read from.
Ultimately, I realized that this “lazy loading” approach is a really bad idea, since I can’t guarantee that the settings have been all migrated! I need them migrated ASAP, so the widget can make use of it.
The final solution was extremely simple, and I should’ve seen it coming. All we do is copy all the settings from the old defaults to the new container (pardon the ugly ObjC):
MCDefaults, as presented in the previous post, is just a convenience method that returns the user defaults associated with the app group identifier.