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];
}
助けてください:私は次のよう持っています。