MVC模式设计?
我刚刚阅读了 Cocoa-Touch 应用程序的 MVC 设计模式,它建议使用模型的属性列表。我的问题是,如果您需要对属性列表中的数据进行一些计算,该计算的代码将放在哪里?
过去,我为我的模型使用了单例对象,然后用它来访问数据并进行任何处理,我只是好奇其他人如何设置它......
加里
I have just been reading about the MVC design pattern for Cocoa-Touch applications and it suggested using a property list for the model. My question is if you needed to do some calculation on the data in the property list where would the code for that calculation go?
In the past I have used a singleton object for my model and then used that to access data and do any processing, I am just curious how others go about setting this up ...
Gary
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为 plist 是模型,它只是存储模型数据的一种方式。它是模型的一部分。您可以使用 SQLite 数据库来存储数据,而无需更改程序的模型。您应该能够更改程序存储信息的方式,而无需更改控制器部件。
plist 适用于少量数据,最多 50 个项目。此后它开始变得难以管理,而数据库是更好的选择。如果您想做搜索或订购数据库可以让您的生活更轻松。
因此,建议模型(存储)的 plist 仅在某些情况下才是正确的。认为 plist是模型并不是完整的图片。
我发现 Big Nerd Ranch iPhone 书 中的 MVC 描述是最好的之一。
I don't think that a plist is a model, it's just a way to store your model data. It's one part of the model. You could use an SQLite database to store the data without changing the model of your program. You should be able to change the way your program stores its information without the controller parts having to change.
A plist is good for a small amount of data, up to around 50 items. It starts to get less manageable after this, and a database is a better option. If you want to do searching or ordering a database can make your life easier.
So suggesting a plist for the model (storage) is only correct in some situations. Thinking that the plist is the model is not the full picture.
I found the MVC descriptions in the Big Nerd Ranch iPhone book to be one of the best.
您可以使用属性列表来存储基本(读取相当平坦)数据。
如果您想从 plist 中读取数据,然后进行计算并将其写回到 plist 中的不同字段中,那应该没问题。
如果通过计算您暗示您需要一个关系数据库,则以下链接提供了存储可可应用程序“模型”部分的选项的简单比较。
http ://tapity.com/iphone-app-development/readwrite-data-on-the-iphone-property-lists-sqlite-or-core-data/
干杯
进化
You can use a Property list for storing basic (read fairly flat) data.
If you want to read from the plist and then do a calc and write that back into a different field in the plist that should be no problem.
If instead by calculations your are implying you want a relational database, the following link provides a simple comparison of options to store the 'models' part of your cocoa app.
http://tapity.com/iphone-app-development/readwrite-data-on-the-iphone-property-lists-sqlite-or-core-data/
Cheers
Evolve