本文介绍了使用NSPersistentCloudKitContainer在用户之间共享核心数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Apple引入了 a>与iOS 13结合使用,这使我们能够将CloudKit与Core Data结合使用。我可以使它在不同设备上立即工作,但主要问题仍然存在。Apple introduced the NSPersistentCloudKitContainer with iOS 13 which enable us to use CloudKit with Core Data. I got it working pretty much instantly on different devices but my main issue is still left.是否可以与其他用户轻松地共享数据? 我一直在阅读 CKShare ,但看不到如何从 NSPersistentCloudKitContainer 转到那Is it possible to share the data in an easy way with other users?I've been reading on CKShare but don't see how I can go from NSPersistentCloudKitContainer to that in an easy way.推荐答案似乎现在可以通过新的在iOS 14.0+ Beta和macOS 11.0+ Beta中实现strong> databaseScope 属性: https://developer.apple.com / documentation / coredata / nspersistentcloudkitcontaineroptions / 3580372-databasescope It seems this is now possible in iOS 14.0+ Beta and macOS 11.0+ Beta via the new databaseScope property: https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontaineroptions/3580372-databasescope可能的值为 .public (公共数据库), .private (私有数据库)和 .shared (共享数据库)。The possible values are .public (the public database), .private (the private database) and .shared (the shared database).例如:let container = NSPersistentCloudKitContainer(name: "test")guard let description = container.persistentStoreDescription.first else {fatalError("Error")}description.cloudKitContainerOptions?.databaseScope = .shared视频 https://developer.apple.com/videos/play/wwdc2020/10650 描述了如何将Core Data存储与CloudKit公共数据库同步通过将 databaseScope 的值设置为 .public 。The video https://developer.apple.com/videos/play/wwdc2020/10650 describes how to sync the Core Data store with the CloudKit public database by setting the databaseScope value to .public. [ UPDATE ]不幸的是,即使 databaseScope = .shared 属性表明并非如此,似乎还不支持共享。请参考 https:// developer .apple.com / forums / thread / 649630?login = true& page = 1#621748022 如下面的Brian M所指出。[UPDATE] Unfortunately, it seems sharing is not (yet?) supported, even though the databaseScope = .shared property suggests otherwise. Please refer tohttps://developer.apple.com/forums/thread/649630?login=true&page=1#621748022 as pointed out by Brian M below. 这篇关于使用NSPersistentCloudKitContainer在用户之间共享核心数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!