Reputation: 7721
If I'm using an NSPersistentCloudKitContainer, I see in the sqlite file that changes are automatically synced. I can also make changes in the CloudKit Dashboard, restart the app and see the changes. If I use @FetchRequest
to load some items, should the items array automatically update?
// Fetch some items
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
animation: .default)
private var items: FetchedResults<Item>
// Show them in a List
List(items) { item in
VStack {
Text("Item at \(item.timestamp!, formatter: itemFormatter)")
}
}
Upvotes: 0
Views: 80
Reputation: 7721
Yes, if you set automaticallyMergesChangesFromParent = true
which is not in the default code provided by Apple when you check Use CoreData and CloudKit.
let container = NSPersistentCloudKitContainer(name: "MyApp")
container.viewContext.automaticallyMergesChangesFromParent = true
Upvotes: 1