2011-11-14 11 views
0

日付カラムと変換可能カラム(NSDictionary)を含むNSManagedObjectがあります。日付カラムと変換可能カラムの両方が、独自のコンテキストでバックグラウンドスレッド上で更新され、その後、メインスレッドのコンテキストにマージされます。日付列は正しく更新されて保存されていますが、Transformable列は正しくありません。変形の列は、このように更新されている:バックグラウンドスレッドコンテキストで変換可能な属性がメインスレッドコンテキストにマージされても保存されない

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
[nc addObserver:self selector:@selector(mergeChanges:) name:NSManagedObjectContextDidSaveNotification object:managedObjectContext]; 
NSMutableDictionary *newUserDataDictionary = [NSMutableDictionary dictionaryWithDictionary:object.userDataDictionary];    
//Updated newUserDataDictionary here 
object.date = calendarDay.date; 
object.userDataDictionary = newUserDataDictionary; 
if (![managedObjectContext save:&error]) { 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

mergeChangesで:

- (void)mergeChanges:(NSNotification *)notification 
{  
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
// Merge changes into the main context on the main thread 
[delegate.managedObjectContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) 
           withObject:notification 
          waitUntilDone:YES]; 
} 

助けてください:私は次のよう持っています。

答えて

0

この問題はmergeChangesFromContextDidSaveNotificationメソッドにある必要があります。このメソッドが呼び出されているかどうかを確認します。はいの場合、問題はそこに存在します。

関連する問題