diff --git a/RMMapper/NSUserDefaults+RMSaveCustomObject.m b/RMMapper/NSUserDefaults+RMSaveCustomObject.m index b2fdc30..3bd17ee 100644 --- a/RMMapper/NSUserDefaults+RMSaveCustomObject.m +++ b/RMMapper/NSUserDefaults+RMSaveCustomObject.m @@ -23,9 +23,14 @@ -(void)rm_setCustomObject:(id)obj forKey:(NSString *)key { -(id)rm_customObjectForKey:(NSString *)key { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSData *encodedObject = [defaults objectForKey:key]; - id obj = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject]; - return obj; + if ([[defaults dictionaryRepresentation].allKeys containsObject:key]) { + NSData *encodedObject = [defaults objectForKey:key]; + id obj = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject]; + return obj; + // unarchive the value here + }else{ + return nil; + } } @end \ No newline at end of file