【问题标题】:NSManagedObjectContextDidSaveNotification with numerous core data storesNSManagedObjectContextDidSaveNotification 与许多核心数据存储
【发布时间】:2013-07-12 17:03:35
【问题描述】:

我的应用中有 2 个独立的数据存储,它们同时进入后台线程。因此我有这个代码来设置它:

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;

这会导致问题,因为两个对象都会收到通知,还是会以不会对任一数据存储产生负面影响的方式处理它?

编辑: 好吧,事实证明这并不好。备择方案?如果我不在后台线程中保存其中一个,它还需要那个通知吗?

【问题讨论】:

    标签: iphone ios objective-c core-data nsmanagedobject


    【解决方案1】:

    我假设您正在从与每个 NSPersistentStoreCoordinator 关联的不同 NSManagedObjectContexts 中查看 NSManagedObjectContextDidSaveNotification

    在对addObserver 的调用中将它们指定为object: 参数而不是nil

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      • 1970-01-01
      • 2010-11-02
      • 1970-01-01
      相关资源
      最近更新 更多