Replies: 1 comment 3 replies
-
|
Hi @pfandrade, thanks for sharing your experiments. I'm not 100% sure I am following though. Which tables do you hand to the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been working on adding CloudKit sync to an app and I just though I'd like to share something I think is pretty cool that's even possible.
This app has a
Wishlisttype that looks like this:The problem is the last two fields:
sortOrderandlistOrder.sortOrderallows the user to manually adjust the order of their wishlists, and it should be synced between his devices but not shared other users.listOrderis just how the items in that list are ordered. This changes often (and could probably be backed by UserDefaults) so it doesn't need to be synced at all.We've seen Brandon and Stephen solve a similar problem by separating the part that doesn't need sync to a different table. My issue was that the rest of the app already expects a
Wishlistto have that layout. And it kind of makes sense that the rest of the app doesn't need to know what's being sync, shared, or just local.So my solution was to create a database view to represent that
Wishlist, that's composed of aCore,PrivateandLocaltables.When setting up the
SyncEnginewe just need to tell it which tables are private, which are synced and don't tell it about the local tables.This works fine for reading, but we still need to insert, edit and delete the
Wishlisttype. Ideally the rest of the app shouldn't need to know this is a database view. Unfortunately, support for these operations on views doesn't exist out of the box in SQLite, but it does support triggers in views.Using triggers we can replace calls to insert update or delete the
Wishlisttype:There are a couple caveats, but I think it's pretty cool that this is even possible! Caveats:
That's it. I just felt this deserved to be shared 😄
Beta Was this translation helpful? Give feedback.
All reactions