title: Core Data not saving transformable NSMutableDictionary
body: <p>I have two classes: Profile and Config. A Profile contains an NSSet of Config objects. Both Profile and Config are <code>NSManagedObject</code> subclasses.</p>
  
  <pre><code>@interface Profile : NSManagedObject
  
  @property (nonatomic, retain) NSString * name;
  @property (nonatomic, retain) NSSet *configs;
  
  - (void)print;
  
  @end
  </code></pre>
  
  <p>Here is the Config class</p>
  
  <pre><code>@interface Config : NSManagedObject
  
  @property (nonatomic, retain) NSString * otherdata;
  @property (nonatomic, retain) NSString * name;
  @property (nonatomic, retain) NSMutableDictionary *myDict;
  @property (nonatomic, retain) Profile *profile;
  
  - (void)print;
  
  @end
  </code></pre>
  
  <p>The dictionary myDict has <code>NSString</code> *keys and values. Now when I make any changes to myDict, I call the <code>NSManagedObject</code> save method and that works fine with no errors. As long as I do not kill the app, everything behaves as expected.</p>
  
  <p>But when I force kill the app (either in Xcode or by double pressing the home button and killing it in the row of buttons at the bottom) and then restart the app, the data in myDict reverts to what was there before, ie the new data was not actually saved. It only appeared to be saved before I killed the app.</p>
  
  <p>myDict is listed as Transformable inside the xcdatamodeld file. I tried it without specifying any <code>NSTransformer</code> class. I also tried it specifying a transformer class MyDictTransformer, and in Config I added this code:</p>
  
  <p>In Config.h:</p>
  
  <pre><code>@interface MyDictTransformer : NSValueTransformer
  
  @end
  </code></pre>
  
  <p>In Config.m:</p>
  
  <pre><code>@implementation MyDictTransformer
  
  + (Class)transformedValueClass
  {
      return [NSMutableDictionary class];
  }
  
  + (BOOL)allowsReverseTransformation
  {
      return YES;
  }
  
  - (id)transformedValue:(id)value
  {
      return [NSKeyedArchiver archivedDataWithRootObject:value];
  }
  
  - (id)reverseTransformedValue:(id)value
  {
      return [NSKeyedUnarchiver unarchiveObjectWithData:value];
  }
  
  @end
  </code></pre>
  
  <p>Also at top of Config.m I have this:</p>
  
  <pre><code>//
  // from: http://stackoverflow.com/questions/4089352/core-data-not-updating-a-transformable-attribute
  //
  
  + (void)initialize {
      if (self == [Config class]) {
          MyDictTransformer *transformer = [[MyDictTransformer alloc] init];
          [NSValueTransformer setValueTransformer:transformer forName:@"MyDictTransformer"];
      }
  }
  </code></pre>
  
  <p>Also in AppDelegate, in both <code>applicationDidEnterBackground</code> and <code>applicationWillTerminate</code> I call <code>saveContext:</code></p>
  
  <pre><code>- (void)saveContext
  {
      NSError *error = nil;
      NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
      if (managedObjectContext != nil)
      {
          if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext save:&amp;error])
          {
              /*
               Replace this implementation with code to handle the error appropriately.
  
               abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
               */
              NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
              abort();
          } 
      }
  }
  </code></pre>
  
  <p>No matter what I have tried, it simply does not save the dictionary in Config. It saves any other changes in things like config.name but not in config.myDict.</p>
  
  <p>A) What am I doing wrong?
  B) How can I fix this, even if I have to use some other data structure than an <code>NSMutableDictionary</code> to save the data?</p>