Objective C (java)Static

So I have wanted some static variables (along the lines that Java implements it).  After a while I found my answer.

DatabaseConfig.h

@interface DatabaseConfig : NSObject {
// Database variables

}

+ (NSString*) databaseName;
+ (void) setDatabaseName:(NSString*)dbName;
+ (NSString*) databasePath;
+ (void) setDatabasePath:(NSString*)dbPath;

DatabaseConfig.m

static NSString *databaseName;
static NSString *databasePath;

@implementation DatabaseConfig

+ (NSString*)databaseName{
return databaseName;
}
+ (void)setDatabaseName:(NSString*)dbName{
databaseName = dbName;
}
+ (NSString*)databasePath{
return databasePath;
}
+ (void)setDatabasePath:(NSString*)dbPath{
databasePath = dbPath;
}

@end

Access them like

#import "DatabaseConfig.h"

NSString *name = [DatabaseConfig databaseName];

(I will look at finding some code markup.. any ideas?)

Posted on February 18, 2009 at 10:47 am by Jordan Carter · Permalink
In: Iphone · Tagged with: 

Leave a Reply