Among the settings that I am saving to NSUserDefaults is a non-mandatory object that doesn't make sense to have an out-of-the-box default. Until the user sets a value for this object, the app generates the error "[NSKeyedUnarchiver initForReadingWithData:]: data is NULL" when I unarchive from NSUserDefaults. I am ignoring the error and the app works fine otherwise.
Is there a best practice to avoid this, and is this a worry?
I'm not sure exactly what you're unarchiving, but if you can look at the keys first, before you unarchive, you could do it like this:
if ([[[NSUserDefaults standardUserDefaults] dictionaryRepresentation].allKeys containsObject:@"keyForNonMandatoryObject"]) {
// unarchive the value here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With