找到你要的答案

Q:When and how should I load data from database into my MVC model?

Q:我应该何时以及如何从数据库中加载数据到我的MVC模式?

I am developing an app which will have numerous user and product information. When I used to develop for desktop or web platforms, I would load all the pertinent data from the database into the model during application initialization. In other words, when the application would load, it will populate the entire Model hierarchy with data from the database. This required more memory but that wasn't an issue on the desktop and web platforms as much. My question is in the iOS platform, should I load only those data that will be presented in the view at any one time to manage memory? Or should I load all the data during app opening and hold the data in memory. Also, I am assuming the data will be loaded at the Model level. Is there any best practice regarding how database data can be loaded into a Model in iOS? Should I make a database call inside init or is there a better way?

我正在开发一个应用程序,将有大量的用户和产品信息。当我用于桌面或web平台开发时,我会在应用程序初始化时将数据库中的所有相关数据加载到模型中。换句话说,当应用程序加载时,它将用数据库中的数据填充整个模型层次结构。这需要更多的内存,但这不是桌面和Web平台上的问题。我的问题是在iOS平台,我应该仅加载这些数据将呈现在视图在任何一个时间内存管理?或者我应该加载所有的数据在应用程序打开和持有的数据在内存中。此外,我假设数据将在模型级别加载。有没有最佳实践有关数据库的数据可以被加载到iOS的模式?我应该在init进行数据库调用或有更好的方法吗?

ios  model-view-controller  load  lazy-evaluation