When I run this :
@interface Database : NSObject {
sqlite3 *database;
}
+(void)openDatabase;
@end
@implementation Database
+(void)openDatabase
{
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *databaseNameandPath = [NSString stringWithFormat:@"%@/DatabaseSnax.sqlite",docDir];
NSString *databasePath=[[NSString alloc]initWithFormat:databaseNameandPath];
if(sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK)
{
NSLog(@"Error when open the database");
}
[databasePath release];
}
I have this error: instance variable database accessed in class method
How I can solve this issue and I need to keep my method (open database) as a static method so I can use it by class name, for example:
[Database openDatabase];