2013-04-16 29 views
1

好的,所以我的问题很简单。我需要我的一个属性是可选的。 10.7以下& 10.8很好,但在Snow Leopard下它崩溃了。当我取消选中“可选”时,它不会再崩溃,但现在保存会导致错误,并且不会发生。Snow Leopard中可选属性崩溃的实体

这是我如何设置管理对象上下文:

self.notesPersistentStore = [self.notesStoreCoordinator 
           addPersistentStoreWithType:NSSQLiteStoreType 
           configuration:nil 
           URL:self.notesStoreUrl 
           options:nil 
           error:nil]; 

_notesContext = [[NSManagedObjectContext alloc] init]; 
_notesContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy; 
[_notesContext setPersistentStoreCoordinator:self.notesStoreCoordinator]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(notesContextChanged:) 
             name:NSManagedObjectContextObjectsDidChangeNotification 
             object:self.notesContext]; 

而这正是它崩溃的部分:

- (void)notesContextChanged:(NSNotification *)notification_ 
{ 
    [self.notesContext save:nil]; 
} 

回答

1

明白了!

雪豹想是保存的NSManagedObjectContext的主线程

dispatch_async(dispatch_get_main_queue(), ^{ 
    NSError *error; 
    [self.notesContext save:&error]; 
    [Utils handleError:error]; 
}); 

上发生,现在的作品!

让我感到困惑的是,如果所有属性都被指定为强制,那么即使在10.6上,它也不会在主线程上运行,而是非常棒。噢...