2013-07-12 28 views
0

我在我的應用程序中有兩個獨立的數據存儲,這兩個數據存儲同時進入後臺線程。因此,我有這樣的代碼來設置它:NSManagedObjectContextDidSaveNotification與衆多的核心數據存儲

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 
    [notificationCenter addObserver:self.dataStoreManager 
          selector:@selector(mergeChanges:) 
           name:NSManagedObjectContextDidSaveNotification 
          object:nil]; 
    NSPersistentStoreCoordinator *dataStoreBackgroundPSC = self.dataStoreManager.managedObjectContext.persistentStoreCoordinator; 

    [notificationCenter addObserver:[AppDelegate applicationDelegate].coreDataManager 
          selector:@selector(mergeChanges:) 
           name:NSManagedObjectContextDidSaveNotification 
          object:nil]; 
    NSPersistentStoreCoordinator *journalDataPSC = [AppDelegate applicationDelegate].coreDataManager.persistentStoreCoordinator; 

這會帶來問題,因爲這兩個對象將收到通知,否則將對待它的方式,也不會數據存儲產生負面影響?

編輯: 好吧,事實證明,這實際上並不好。備擇方案?如果我不在後臺線程中保存其中的一個,它是否仍然需要該通知?

回答

1

我假設您正在查看與每個NSPersistentStoreCoordinator相關聯的不同NSManagedObjectContextNSManagedObjectContextDidSaveNotification

在您撥打addObserver的電話中指定這些參數爲object:參數而不是nil