在我的应用程序中,我将数据与核心数据一起存储。最近我发现了 Apple 在 WWDC19 中引入的新功能,它允许核心数据与 CloudKit 一起使用。我刚刚为我的应用程序启用了 cloudKit,并使用了 NSPersistentCloudKitContainer 而不是 NSPersistentContainer,一切都设置好了!我的所有数据都在 ios 设备之间共享。这与 NSPersistentContainer 类似,但它会在 icloud 服务器上发送更改的副本,因此始终存在本地数据缓存。
现在我想从我的 Apple Watch 配套应用程序访问这些数据,但不是所有的数据,只有一个特定的实体!那我怎么能这样做呢?我尝试使用属性检查器设置在两个目标之间共享的 NSPersistentCloudKitContainer,但看不到任何数据。我可以在 cloudKit 仪表板中看到有来自 watchOS 的请求,但 watch 没有获得任何数据。
但是如果我将手表中的实体保存到核心数据中,我只能从手表中获取它。我的结论是两者都没有将数据存储在同一个地方。那么我该如何解决呢?已经有使用相同的 NSPersistendCloudKitContainer。
两个目标之间共享的容器:
import Foundation
import CoreData
public class CoreDataContainer {
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could …Run Code Online (Sandbox Code Playgroud) 在 iOS 13 及更早版本中,我们可以使用 UIDatePicker 作为 inputView 但现在呢?
我尝试使用 ios14,但在点击文本字段时没有任何附加内容。
var timePicker = UIDatePicker()
self.timePicker.preferredDatePickerStyle = UIDatePickerStyle.wheels
self.timePicker.datePickerMode = UIDatePicker.Mode.time
self.timePicker.minuteInterval = 5
self.startTimeTxtField.inputView = self.timePicker
Run Code Online (Sandbox Code Playgroud)
正常吗?