Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[NSKeyedUnarchiver initForReadingWithData:]: data is NULL

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?

like image 662
Michael Mangold Avatar asked Jun 04 '13 22:06

Michael Mangold


1 Answers

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
    }
like image 68
rdelmar Avatar answered Nov 15 '22 13:11

rdelmar