Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The pattern I follow to avoid these situations is as follows:</p> <p>In my ApplicationDelegate <code>+(void)initialize</code> method I set up the keys and their defaults like so to ensure nothing attempts to touch the defaults before they are setup:</p> <pre><code>+(void)initialize { NSDictionary *factoryPrefs = @{MyNewPrefKey:@"ANewPrefKeyDefaultValue"}; } [[NSUserDefaults standardUserDefaults] registerDefaults:factoryPrefs]; userSettings = [NSUserDefaults standardUserDefaults]; </code></pre> <p>Next, and immediately after this I have a block of code that based on current version, starts checking for the existence of previous values that imply a user was upgrading (not new). In that case I'm going to have to migrate/update the prefs.</p> <p>For example, sometimes keys have to be altered or values inserted like if you stored an NSDictionary object with value a, b, c in it in some previous version, but now in this Ver. your depending on (and assuming) a 'd' value is also in there.</p> <p>In that case <code>registerDefaults</code> is NOT going to help because as you noted the value was previously created. So YOU have to manually check if 'd' is in there and if NOT insert it with along with the default value. This is sort of the CoreData migration equivalent for Prefs :)</p> <p>That is what I do. I do it religiously. I check it EVERY release, because... I was burnt, just like you previously by NOT doing it. And then we all know what happens next, you get a serious 1 star a.. whooping in the App Store.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload