CloudKit - What to do when a user adds, modifies o

2019-05-21 03:12发布

问题:

I am running into the issue of what to do when a user does a delete, for example, while offline? I was considering using an addedQueue, modifiedQueue, and deletedQueue, and persisting them using NSCoding and NSKeyedArchiver. Maybe I would use a Set or a Dictionary. Then I would iterate over them in the background or once every app launch, and remove from them on success. Does that sound reasonable? Does anyone have experience with this problem they can share? I've done quite a bit of searching for answers, including watching all the CloudKit WWDC talks.

I am storing all of my data locally using Core Data, so I thought about adding a property for add or modify, but it wouldn't work so well for delete.

回答1:

What about a separate database table (i.e. Core Data Entity) for queued changes?

You could have separate ones for each action (as you describe), or else have a single property (such as 'action') on the queued change entity object. Then you could either try regularly, you could check for connectivity before trying to sync the changes, and yes, as you said, iterate over them and clear them on success.