Where does the 'method' implementation go? (I'm a newbie)
I have this code:
#import "SQLiteDB.h"
@implementation SQLiteDB
@synthesize db, dbPath, databaseKey;
@end
//-------------- check for database or create it ----------------|
- (void)checkForDatabase {
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *databaseP开发者_运维知识库ath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingString:@"/ppcipher.s3db"];
if(![filemanager fileExistsAtPath:databasePath]) { //Database doesn't exist yet, so we create it...
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/ppcipher.s3db"];
sqlite3 *db;
if(sqlite3_open(databasePath, db) == SQLITE_OK) {
}
}
}
It's complaining that "method definition not in @implementation context". So where does it go? (I tried in the .h file, but still get the error)
The method implementation must occur between the @implementation
and the @end
. That is:
#import "SQLiteDB.h"
@implementation SQLiteDB
@synthesize db, dbPath, databaseKey;
-(void) checkForDatabase {
...
}
@end
it should be inside @implementation block
#import "SQLiteDB.h"
@implementation SQLiteDB
@synthesize db, dbPath, databaseKey;
//-------------- check for database or create it ----------------|
- (void)checkForDatabase {
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingString:@"/ppcipher.s3db"];
if(![filemanager fileExistsAtPath:databasePath]) { //Database doesn't exist yet, so we create it...
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/ppcipher.s3db"];
sqlite3 *db;
if(sqlite3_open(databasePath, db) == SQLITE_OK) {
}
}
}
@end
精彩评论