2011-03-08 19 views
0

我有這樣的代碼:'方法'實現在哪裏? (我是新手)

#import "SQLiteDB.h" 

@implementation SQLiteDB 

@synthesize db, dbPath, databaseKey; 

@end 



//-------------- 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) { 

     } 

    } 
} 

它抱怨說「法的定義不@implementation上下文」。那麼它到底在哪裏? (我在.h文件中試過,但仍然出錯)

+1

多德 - 去閱讀:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual /ObjectiveC/Introduction/introObjectiveC.html – bbum 2011-03-08 02:22:07

回答

3

該方法的實現必須發生在@implementation@end之間。那就是:

#import "SQLiteDB.h" 

@implementation SQLiteDB 

@synthesize db, dbPath, databaseKey; 

-(void) checkForDatabase { 

    ... 

} 

@end 
1

應該是裏面@implementation塊

#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 
相關問題