views:

121

answers:

3

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.

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.

A: 

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.

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

Carl Coryell-Martin
+1  A: 

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.

drewh
A: 

With http://ODBCrouter.com/ipad (new), you can now do the same kind of thing you were doing in .NET --there are XCode libraries, headers and an Objective C "singleton" class [ODBCRouter] that allows you to send SQL queries to just about any database server and get back binary results directly into your program variables. Best of all, it is multi-threaded, meaning your app can (if it wants to) do other things, even other database operations, at the same time (but if you just want to wait synchronously for the results to come back, it does that too, even optionally popping-up a spinner if the query starts to take too long and pulling it down and sending you a notification when it's completed.) There are screenshots of it in action at that link. The server-side runs on Windows (along with your database's official ODBC driver) but the database itself may reside on Mac OS X, Windows, Linux, IBM iSeries or AS/400, Unix, NetWare, DOS and legacy mainframes with support for most revisions of MySQL, 4D, QuickBooks Pro, DB/2, MYOB, Empress, Oracle, SQL Server, MS Access, Excel, Navision, Firebird, Pervasive, Sybase, Pick, Universe, Informix, Ingres and SQLite among many others.

AugSoft Tom