![]() ![]() Step 6: Never forget to deploy your updated schema from the CloudKit Dashboard ![]() Not instantaneous, but a handful of seconds instead of requiring me to sometimes force quit and restart the app (or switch tabs or something) to see changes. However-and maybe it’s some sort of weird placebo effect-it seemed like changes from my watch synced much more quickly to my phone. I’ve seen a few folks say that merging changes like this shouldn’t be necessary. #Swift share core data with extension codeApple’s code has a bunch of deduplication logic in it that frankly, I’m not emotionally ready to process, so I skipped it. Most of that code was pulled from Stack Overflow. rgeChanges(fromRemoteContextSave: userInfo, into: ) In Apple’s sample code, you’ll notice that within the persistent container’s lazy initialization, two options are set on the container’s description. Step 1: Make your container lazy and set some important options If you use the template, that becomes a struct called “PersistenceController.” I’m sure the struct is SwiftUI-ier, but the class from Apple’s sample code (which does not use SwiftUI) makes more sense to my brain, so I went with that. My SwiftUI app was created before Apple even added a SwiftUI + Core Data project template, so I created a class called “CoreDataStack” that has a shared instance. To figure out what that work is, you can’t look at Apple’s Core Data templates. Turns out, if you want to sync Core Data-backed data between devices and have those changes reflected in your UI in a timely manner, you have some more work to do. Boom, done! And in fact, Apple’s “Core Data –> Host in CloudKit” SwiftUI project template does those things for you, so you’re good to go, right? When Apple introduced changes to Core Data + CloudKit integration in 2019, they sold developers on a dead-simple API: add iCloud sync to your Core Data app with “as little as one line of code.” That one line, of course, is simply changing NSPersistentContainer to NSPersistentCloudKitContainer and enabling a few capabilities in the project settings. Also if you’re an Apple engineer…I’m sorry. This right here is just pure dumpster fire all the way down. ![]() Note: This was posted before WWDC 2021, so if major changes were made to Core Data + CloudKit, they aren’t reflected here. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |