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.
@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?)
Related Posts
In: Iphone · Tagged with: Objective C