Posts

Post not yet marked as solved
2 Replies
129 Views
Hey, I'm currently working on adding CloudKit support to the GRDB SQLite database in my app. CKSyncEngine, though still a bit tricky to wrap your head around, is amazing! I have most of the basic setup implemented and some very easy cases already work, which is really exciting! However, I do have some questions regarding data consistency across devices. I'm not sure though, that these questions are actually "correct" to ask. Maybe my entire approach is inherently flawed. Say we add two records to the pending changes of the sync engine: // I'm simplifying CKRecord.ID to be a String here syncEngine.state.add(pendingRecordZoneChanges: [.saveRecord("1"), .saveRecord("2")] Let's also say that both records are tightly connected. For example, they could be in a one-to-one relationship and must always be added to the database together because the app relies on the existence of either none or both. After that call, at some later point, the system will call the sync engine's delegate nextRecordZoneChangeBatch(_:syncEngine:) for us to batch the changes together to send to iCloud. First question: Can we guarantee that records "1" and "2" always land in the exact same batch, and are never separated? Looking at the example code, there are two line that worry me a bit: // (Sample project: `SyncedDatabase.swift, lines 132-133`) let scope = context.options.scope let changes = syncEngine.state.pendingRecordZoneChanges.filter { scope.contains($0) } The scope could lead to one of the two records being filtered out. However, my assumption is that the scope will always be .all when the system calls it from an automatically managed schedule, and only differs when you manually specify a different value through calling syncEngine.sendChanges(_:). Is that correct? Now back to the example. Say we successfully batched records "1" and "2" together and the changes have been sent to iCloud. Awesome! What happens next? Other connected devices will, at some point, fetch those changes and apply them to their respective local databases. Second question: Can we guarantee that iCloud sends the exact same batches from earlier to other devices and does not create new batches from all the changes? I'm worried that iCloud might take all stored changes and "re-batch" them for whatever reason (efficiency, for example). Because that could cause records "1" and "2" to be separated into different batches. A second device could end up receiving "1" and, for at least some period of time, will not receive "2", which would be an "illegal" state of the data. I'd appreciate any help or clarification on this :) Thanks a lot!
Posted
by Quantm.
Last updated
.
Post not yet marked as solved
1 Replies
482 Views
Hey, I've been using watchOS 7 for the past week and it mostly works fine. There's one strange thing, though. About once a day, the watch connects to our wifi as a new device or something. There's a feature on the router informing about new devices connecting so I noticed that. This hasn't happened before the beta. One thing to note: The "as a new device" part is an interpretation by me. I don't know if it's actually like this. At least it gets a new ip address every time. Also, known devices that are reconnecting don't usually cause the router to notify us. Any idea what's causing this? Thanks!
Posted
by Quantm.
Last updated
.
Post marked as solved
1 Replies
689 Views
Hey, I love the new changes in SwiftUI! Though, I have one question about the use of Core Data: When you create a new SwiftUI project and choose the new default life cycle "SwiftUI App", there's no option to use Core Data anymore. It's grayed out. Are there any reasons behind this? And does this mean, Core Data isn't intended for use with SwiftUI anymore? Or will it be enabled later or something? If Core Data isn't meant to be used anymore in SwiftUI, what are alternatives to properly store persistent data? Thanks and have a great day!
Posted
by Quantm.
Last updated
.