There is a method [NSUserDefaults resetStandardUserDefaults]
which completely removes all stored settings.
Your solution regarding versioning is completely right, you can keep your app version within NSUserDefaults, check it on every app launch, do migration if the version is different and store your current app version back. If there's no version in NSUserDefault then it's a fresh installation launch, so you do not do anything.
Once I had to implement a similar mechanism for version-to-version migrations, because if you update your app more than once and you need some data migration on every update then you need more powerful mechanism, not just a flag that says same version or not. so I wrote two functions that split and compare a version string on N components. version_compare
can be also used in NSArray sort operations, so I had basically special object that performed data migration for each version, I was looking for current version, sorting all released versions of the app and incrementally performing migration.
#define MAX_VERSION_DIGITS 3
static void parse_version_string(NSString* version, int(*numbers)[MAX_VERSION_DIGITS])
{
int seq[MAX_VERSION_DIGITS] = { 0, 0, 0 };
NSArray* split = [version componentsSeparatedByString:@"."];
for(int i = 0, c = MIN(MAX_VERSION_DIGITS, split.count); i < c; i++)
{
seq[i] = [[split objectAtIndex:i] intValue];
}
memcpy(numbers, &seq, sizeof(seq));
}
static NSComparisonResult version_compare(NSString* a, NSString* b)
{
int seq1[MAX_VERSION_DIGITS];
int seq2[MAX_VERSION_DIGITS];
parse_version_string(a, &seq1);
parse_version_string(b, &seq2);
for(int i = 0; i < MAX_VERSION_DIGITS; i++)
{
if(seq1[i] > seq2[i])
{
return NSOrderedDescending;
}
else if(seq1[i] < seq2[i])
{
return NSOrderedAscending;
}
}
return NSOrderedSame;
}