Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

binjaja

macrumors newbie
Original poster
Nov 13, 2008
10
0
I read the SQLITE3 example and the AppDelegate is used to open the SQLite datbase and it is also used to initiate all database activity.

However, in my application , I have multiple view controllers and depending on user input , all of the view controllers would like to modify or read the database.

My question is...how do you share an sqlite3* object between view controllers? In the SQLITE3 example they declare

sqlite3* database

in the AppDelegate and they assign to "database" using a C function call and passing it "&database". Then , AppDelegate
opens the database.

So how do my other view controllers get access to this?If I have a different view controller, I thought that I could put code in the AwakeFromNib that could message the AppDelegate for the database pointer. Then, I could assign the result to a local sqlite3* database variable in my view controller .Would that work? Is that necessary? Am I missing something simple? How do you make database queries from multiple view controllers without having to use the AppDelegate as the central point of control?
 
I would just put the sqlite3 database pointer in your app delegate. You can access it with:

Code:
YourAppDelegate *delegate = (YourAppDelegate*)[[UIApplication sharedApplication] delegate];

Then you can access it as a property. Do all your database editing in the same thread to avoid thread safety issues.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.