【发布时间】:2015-08-12 14:58:33
【问题描述】:
我有一个 iPhone (iOS 8) 和 Apple Watch (watchOS 1) 应用程序,它们使用 Core Data(SQLite 商店,放置在共享应用程序组中)共享其数据。两个应用程序都使用共享框架中的相同数据访问代码。 NSPersistentStoreCoordinator 的设置方式如下:
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
let sharedContainerURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(self.sharedAppGroup)!
let storeURL = sharedContainerURL.URLByAppendingPathComponent(self.databaseName)
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
var error: NSError? = nil
if coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: &error) == nil {
fatalError("Unable to add persistent store: \(error)")
}
return coordinator
}()
据我了解,在运行时每个应用程序都有自己的 NSPersistenStoreCoordinator 实例(因为 iPhone 应用程序和 WatchKit 扩展确实有完全独立的地址空间),但这两个连接到完全相同的 SQLite 数据库文件。
当 Watch 应用更改公共 SQLite 存储中的某些数据时如何通知 iPhone 应用,反之亦然:当 iPhone 应用更改公共持久存储中的某些数据时如何通知 Watch 应用?
【问题讨论】:
标签: ios core-data watchkit apple-watch