Reputation: 4984
Here's my code... my problem is that I don't know how to call this (checkIfDatabaseExists) from AppDidFinishLaunching in my AppDelegate.m file.
#import "SQLiteDB.h"
static SQLiteDB *sharedSQLiteDB = nil; // makes this a singleton class
@implementation SQLiteDB
@synthesize db, dbPath, databaseKey;
//-------------- check for database or create it ----------------|
#pragma mark Singleton Methods
+ (SQLiteDB *) sharedSQLiteDB {
if(!sharedSQLiteDB) {
sharedSQLiteDB = [[SQLiteDB alloc] init];
[sharedSQLiteDB checkIfDatabaseExists]; // check to see if d/b exists
}
return sharedSQLiteDB;
}
Upvotes: 1
Views: 60
Reputation: 34263
You can try:
[[SQLiteDB sharedSQLiteDB] checkIfDatabaseExists];
sharedSQLiteDB
is a class method that implements the Singleton design pattern. (or shared instance in Cocoa).
You can learn more about that here: http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Singleton.html
Basically this pattern assures that there is only one object of a certain class instantiated during runtime.
Upvotes: 1
Reputation: 16938
In your app delegate file, import SQLiteDB.h then call
SQLiteDB *db = [SQLiteDB sharedSQLiteDB];
Is that what you meant?
You declared sharedSQLiteDB
as a class method (that leading + sign), so you invoke that on the class (as above). Your call to checkIfDatabaseExists suggests that that is an instance method (declared with a -).
I would suggest naming your static SQLiteDB instance with a leading _ or something to distinguish it from the method named sharedSQLiteDB. It's confusing otherwise.
Am I missing something or does this help?
Upvotes: 2
Reputation: 89232
You call a static message with [ClassName messageName]
, so:
SQLiteDB* sdb = [SQLiteDB sharedSQLiteDB];
Upvotes: 2