使用核心数据实现 iPhone 聊天应用程序的建议
我正在开发一个将使用 Core Data API 的聊天应用程序。
当用户聊天时,我需要将聊天内容保存到数据库中(在本例中为核心数据)。任何人都可以建议我如何实现最佳数据管理,或者如果我不使用核心数据框架,是否有其他方法来存储聊天内容?
我的具体问题是:我应该使用什么策略来跟踪聊天,同时避免数据库中任何类型的数据过载?
我想保存有限的聊天记录,当用户想要查看旧的聊天记录时,他可以向服务器发送请求,该服务器将使用 UITableView 的延迟加载概念填充聊天表。
我正在寻找一些广泛的指导。
I am working on an chat app that will use Core Data API.
When user chats, I need to save the chats into the database (Core Data in this case.) Can any one suggest how I can achieve best data management or is there any alternate way to store chat if I don't use Core Data framework?
My specific question is: What strategy should I use to keep track of chats and at the same time avoid any kind of data over load in the database?
I want to save limited chats and when user wants to see old chats, he can send a request to a server which will fill the table with chats using the lazy loading concept of UITableView.
I am looking for some broad guidance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Core Data 中没有任何特定的聊天应用程序。 Core Data 是一个数据建模 API,这意味着它可以建模或模拟应用程序可能需要的任何类型的运行时数据。
所有严肃的编程都是从数据模型开始的。一旦数据模型完成,应用程序的内部就完整了。
要创建数据模型,您需要坐下来,弄清楚您的数据模型在抽象中是什么样子,即不要担心 API 或代码等细节,只需担心所有数据块如何组合在一起。
考虑与聊天相关的所有部分和信息。对于新手,我建议准备一套索引卡。每张卡片代表一个对象,您将对象的属性写在卡片上。预计会经历很多卡片。
从顶部开始。首先,您有一个
聊天
。然后将Chat
作为属性,例如Participants
、StartTime
、EndTime
LineText
等。 code>Participants 将具有Name
、ChatAddress
等属性。同样,这个想法是要抽象地理解建模和持久化所需的所有数据聊天适合在一起在您开始担心实施细节之前。换句话说,您需要一个非常抽象的模型,原则上它可以指导用任何语言或 API 编写的聊天的设计。在开始编码之前,您确实需要了解这一点。
一旦您弄清楚抽象聊天的数据如何组合在一起,您就可以开始将其映射到核心数据中的实体及其属性。完成后,您的应用程序就完成了 50%。剩下的只是界面。
There is nothing chat app specific in Core Data. Core Data is a data modeling API which means it can model or simulate any type of runtime data an app might need.
All serious programing starts with the data model. Once the data model is complete, the guts of the app are complete.
To create a data model, you need to sit down and figure out what your data model will look like in the abstract i.e. don't worry about specifics such as the API or the code just worry about how all the data pieces fit together.
Think about all the parts and information associated with a chat. For novices, I recommend setting down with a set of index cards. Each card represents an object and you write the objects properties down on the card. Expect to go through a lot of cards.
Start at the top. Firstly, you have a
Chat
. Then aChat
as properties likeParticipants
,StartTime
,EndTime
LineText
etc.Participants
will have properties likeName
,ChatAddress
etc.Again, the idea is to get an abstract understanding of how all the data needed to model and persist a chat fits together before you start worrying about implementation details. In other words, you want an model so abstract that it could in principle guide the design of a chat written in any language or API. You really need that understanding before you start coding.
Once you figure out how the data of an abstract chat all fits together, then you can start mapping that to entities and their properties in Core Data. Once you have that done, your app is 50% complete. The rest is just interface.