我在哪里将数据层放在iPhone App中

时间:2022-04-01 18:02:17

In .Net I usually create a separate class library and reference it in my project. This class library does all the select, insert and updates to the database. Or, I put classes or static methods in the App_Code folder.

在.Net中,我通常会创建一个单独的类库,并在我的项目中引用它。此类库执行对数据库的所有选择,插入和更新。或者,我将类或静态方法放在App_Code文件夹中。

In iPhone Dev, where do I put this data layer in order to have a separation in code and logic. This layer, files, would be accessed by all the views, controllers that need data and want to write to the database.

在iPhone Dev中,我在哪里放置这个数据层,以便在代码和逻辑中分离。所有视图,需要数据并希望写入数据库的控制器都可以访问此层文件。

2 个解决方案

#1


What you are talking about is the Model part of MVC. I typically have a Class for each major table in my database that has all the necessary methods for handling that table.

你在谈论的是MVC的Model部分。我通常为数据库中的每个主表都有一个Class,它具有处理该表的所有必要方法。

So I have GeoNames.m/.h that interacts with my geonames table is sqlite and provides hydrate/dehydrate, query and misc helper methods.

所以我有GeoNames.m / .h与我的geonames表交互是sqlite并提供水合物/脱水,查询和misc辅助方法。

#2


You may also want to consider leveraging CoreData for your DAL. We implemented something very similar to what Carl described in our app, and although it works, you end up reinventing the CoreData wheel.

您可能还想考虑为您的DAL利用CoreData。我们实现了与卡尔在我们的应用程序中描述的非常类似的东西,虽然它有效但最终重新发明了CoreData轮。

#1


What you are talking about is the Model part of MVC. I typically have a Class for each major table in my database that has all the necessary methods for handling that table.

你在谈论的是MVC的Model部分。我通常为数据库中的每个主表都有一个Class,它具有处理该表的所有必要方法。

So I have GeoNames.m/.h that interacts with my geonames table is sqlite and provides hydrate/dehydrate, query and misc helper methods.

所以我有GeoNames.m / .h与我的geonames表交互是sqlite并提供水合物/脱水,查询和misc辅助方法。

#2


You may also want to consider leveraging CoreData for your DAL. We implemented something very similar to what Carl described in our app, and although it works, you end up reinventing the CoreData wheel.

您可能还想考虑为您的DAL利用CoreData。我们实现了与卡尔在我们的应用程序中描述的非常类似的东西,虽然它有效但最终重新发明了CoreData轮。