Objective-c/MVC - 在哪里放置 CRUD
我是新iPhone开发和MVC。 我正在开发一个通过 http(REST/JSON) 与服务器通信的应用程序。 我想知道将我的 CRUD 方法(处理传入和传出服务器的数据)放在哪里 - 模型或控制器。 经验丰富的 iPhone 开发人员会做什么?
I am new iPhone development and MVC.
I am working on a app that communicates with a server via http(REST/JSON).
And i am wondering where to put my CRUD methods, (which handles data coming and going to the server) - model or controller.
What does the experienced iPhone dev´s do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常持久化操作总是发生在MVC的模型中。最好将控制仅限于业务逻辑。
Usually persistence operations always take place in the Model in MVC. Its best to limit the control to business logic only.
就框架而言,您必须构建自己的模型层,要么使用核心数据,要么使用数据管理单例,或者类似的东西。它不像某些 MVC 框架,有一个模型文件目录。
也就是说,您的 Web 客户端业务将采取一些控制器操作来完成 - 也许它们会在您的视图加载时触发,或者在点击按钮时触发,或者您有什么。因此,我通常将 CRUDing 操作功能放在当时呈现的任何视图的控制器中,并根据我返回的内容填充我的模型层。
查看 ASIHTTPRequest 和 JSON Framework 库,因为它们对于我构建这些东西来说绝对是核心。
The way the framework comes to you, you sort of have to build your own Model layer, either out of Core Data or a data management singleton, or something like that. It's not like some MVC frameworks, where there's a directory of files that are the models.
That said, your web client business is going to take some controller actions to accomplish--maybe they fire when your view loads, or when a button is tapped, or what have you. So I usually put the actions-of-CRUDing functionality in the Controller of whatever view is presented at the time, and populate my Model layer depending on what I get back.
Check out the ASIHTTPRequest and JSON Framework libraries, as they're absolutely central to my building these sorts of things.
如果你想使用纯REST api,我建议使用 Restkit 或 ObjectiveResource。
If you want to use pure REST api, I suggest to use Restkit or ObjectiveResource.