I have just started an app in which i am going to use an SQLlite database. It seems there are two key objects you need to access the database once you have opened it.
NSString *databasePath;
sqlite3 *contactDB;
I open the database on the loading screen but need to have the database accessible to all viewcontrollers in the app. I have tried passing the databasePath and contactDB variables through the prepareForSegue method. This works but seems a little ugly.
Is there any way to instantiate these two variables as some kind of whole app global variable so I can do something like:
NSString *databasePath;
sqlite3 *contactDB;
I open the database on the loading screen but need to have the database accessible to all viewcontrollers in the app. I have tried passing the databasePath and contactDB variables through the prepareForSegue method. This works but seems a little ugly.
Is there any way to instantiate these two variables as some kind of whole app global variable so I can do something like:
Code:
[B]mymainViewController.h
[/B]
veryGlobal NSString *databasePath;
veryGlobal sqllite *contactDB
[B]mymainViewController.m
[/B]
- (void)viewDidLoad
{
//initialise and open database here
}
[B]secondViewController.h
[/B]
veryGlobal NSString *databasePath;
veryGlobal sqllite *contactDB
[B]secondViewController.m
[/B]
-(void)printSomeData
{
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
//print data from contactDB here
}
}
Last edited: