CloudKit-当用户离线时添加,修改或删除对象时该怎么办? [英] CloudKit - What to do when a user adds, modifies or deletes an object while offline?

查看:119
本文介绍了CloudKit-当用户离线时添加,修改或删除对象时该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,例如当用户离线时进行删除时该怎么办?我当时正在考虑使用addQueue,modifiedQueue和DeletedQueue,并使用 NSCoding NSKeyedArchiver 来持久化它们。也许我会使用Set或Dictionary。然后,我将在后台或每次启动应用程序时遍历它们,并在成功后将其从中删除。听起来合理吗?有没有人可以分享这个问题的经验?我已经做了很多寻找答案的工作,包括观看了所有CloudKit WWDC的谈话。

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.

我正在使用Core Data在本地存储所有数据,所以我认为有关添加属性以进行添加或修改的操作,但对于删除操作而言效果不佳。

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.

推荐答案

单独的数据库又如何呢?表(即核心数据实体)中是否有排队的更改?

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

您可以为每个操作(如您所描述的)使用单独的属性,或者在排队的更改实体对象上使用单个属性(例如 action)。然后,您可以定期尝试,也可以在尝试同步更改之前检查连接性,是的,正如您所说,对它们进行迭代并在成功后将其清除。

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.

这篇关于CloudKit-当用户离线时添加,修改或删除对象时该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆