Я не понимаю, "почему" SQLiteDB может не отвечать на "-checkIfDatabaseExists". Что вызывает это и как я могу это исправить? (Я очень близок к тому, чтобы заставить это работать, но поскольку я новичок, у меня все еще есть проблемы).
Я ценю любую помощь, которую я могу получить в этом. Вот код:
#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];
}
return sharedSQLiteDB;
}
+(id)allocWithZone:(NSZone *)zone {
if(!sharedSQLiteDB) {
sharedSQLiteDB = [super allocWithZone:zone];
return sharedSQLiteDB;
}
else {
return nil;
}
}
-(id)copyWithZone:(NSZone *)zone {
return self;
}
-(void) release {
// no-op
}
- (void) checkIfDatabaseExists {
// Get the path to the database file
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
NSString *databasePath = [documentPath stringByAppendingPathComponent:@"ppcipher.s3db"];
// Open the database file
const char *cDatabasePath = [databasePath cStringUsingEncoding:NSUTF8StringEncoding];
if(sqlite3_open(cDatabasePath, &db) == SQLITE_OK) // does it exist?
return;
else { // create database file here
}
}
@end
