开发者

Objective-c/MVC - where to put CRUD

开发者_运维知识库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?


Usually persistence operations always take place in the Model in MVC. Its best to limit the control to business logic only.


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.


If you want to use pure REST api, I suggest to use Restkit or ObjectiveResource.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜