title: Why does NSUserDefaults fail to save NSMutableDictionary?
body: <p>I’m trying to save a <code>NSMutableDictionary</code> with <code>NSUserDefaults</code>. I read many posts on the topic in stackoverflow... I also found one option that worked; however unfortunately it worked only once and then it started to save (null) only.
  Does anybody have a hint?</p>
  
  <p>Thanks</p>
  
  <p>Code to save:</p>
  
  <pre><code>[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dictionary] forKey:@"Key"];
  [[NSUserDefaults standardUserDefaults] synchronize];
  </code></pre>
  
  <p>Code to load:</p>
  
  <pre><code>NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
  NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:@"Key"];
  dictionary = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  </code></pre>
  
  <p>Code to add Objects to the <code>NSMutableDictionary</code>:</p>
  
  <pre><code>[dictionary setObject:[NSNumber numberWithInt:0] forKey:@"Key 1"];
  [dictionary setObject:[NSNumber numberWithInt:1] forKey:@"Key 2"];
  [dictionary setObject:[NSNumber numberWithInt:2] forKey:@"Key 3"];
  </code></pre>
  
  <p>Code to NSLog() values:</p>
  
  <pre><code>for (NSString * key in [dictionary allKeys]) {
      NSLog(@"key: %@, value: %i", key, [[dictionary objectForKey:key]integerValue]);
  }
  </code></pre>
  
  <p>And also the keys are (null):</p>
  
  <pre><code>NSLog(@"%@"[dictionary allKeys]);
  </code></pre>