在我的应用程序中,我NSPersistentCloudKitContainer
通过以下方式进行了设置:
let container: NSPersistentCloudKitContainer
init() {
self.container = NSPersistentCloudKitContainer(name: "Model")
self.container.persistentStoreDescriptions[0].setOption(
true as NSNumber,
forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey
}
self.container.loadPersistentStores { (_, error) in
guard error == nil else {
print("error loading store: \(error.debugDescription)")
return
}
}
self.container.viewContext.automaticallyMergesChangesFromParent = true
}
当我在我的 iOS 目标中对容器的上下文调用 fetch 请求时,它按预期工作。但是,当我在 Widget 目标中执行相同的 fetch 请求时,它会返回一个空数组结果。
在我的 iOS 目标中,我有后台模式/远程通知和 iCloud/CloudKit 功能。在我的 Widget 目标中,我具有 iCloud / CloudKit 功能。
不知道为什么它不起作用,所以任何帮助将不胜感激,谢谢!