iOS应用程序数据更新设计模式
我正在开发一个 iOS 应用程序,它基本上是“每日提示”的东西。数据库中已有大约 3500 个提示。每天都会添加新的提示。
我的想法是将 3500 个提示存储在 NSMutableArray 或 NSMutableDictionary 中。由于源数据每天都会增长,因此我需要一种模式来尽可能无缝地保持应用程序数据结构中的数据同步。
在应用程序启动时类似这样的事情吗?
获取数组或字典中最后一条记录的 id
如果存在更多不在数组中的记录,则获取它们并将其作为对象追加到数组中。这些对象将包含数据库记录 ID、技术提示标题和技术提示文本。
我走在正确的轨道上吗? NSMutableArray VS.NSMutableArray NSMutableDictionary?
谢谢!
什么设计模式最适合这个?
I am working on an iOS app that is basically a "tip of the day" thing. There are about 3500 tips already in the database. Every day, there will be a new tip added.
My idea is to store the 3500 tips in an NSMutableArray or NSMutableDictionary. Since the source data will grow daily, I'll need a pattern to keep the data in the app's data structure in sync as seamlessly as possible.
Something like this, on app launch?
Get id of last record in the array or dictionary
If more records exist that are not in the array, get them and append to array as objects. The objects will contain the db record id, tech tip title and tech tip text.
Am I on the right track here? NSMutableArray VS. NSMutableDictionary?
Thanks!
What design pattern fits this best?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最简单的方法是,每次保存数据库中的某些内容时将令牌保存到数据库并将所有更改的对象与其关联。当客户端请求新数据时,它将最后获得的令牌传递给服务器,并且服务器响应与自客户端给出的令牌以来生成的令牌关联的对象。
如何在客户端存储数据是您必须做出的决定。但它不是关于使用 NSMutableArray 或 NSMutableDictionary 的问题,而是如何将其保存在设备上。我建议您查看 CoreData,但也可以直接使用 SQLite 或 plist。
当然,您可以同时使用字典和数组。即您可以有一个大数组,其中所有条目均按日期排序,并将相同的条目对象放入带有日期键的字典中。
I think the easiest would be, to save a token to the DB every time something in the DB was saved and associate all changed object to it. When the client ask for new data, it passes the last token it got to the server and the server response with the objects associated with the tokens generated since the token that was given by the client.
How you store the data client side is a decision you have to make. But it is not about using NSMutableArray or NSMutableDictionary, but how to save it on the device. I'd suggest you to have a look into CoreData, but also direct SQLite or plist might be possible.
And of course you can use dictionary and arrays at the same time. i.e. You could have a big array with all entries ordered by date and put the same entry objects into a dictionary with keys for the date.