I’m defining some simple variables in a class of type NSString
one of them is keeping my sqlite database path for example, and so on…
I am initializing that in the AppDelegate , function didFinishLaunchingWithOptions
and when I’m trying to see it’s value outside this function… it’s losing it’s value durring runtime, (no I’m not overwrting or anything…)
here’s my code…
app.h file
@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
.....................
NSString *site_domain;
NSString *databaseName;
NSString *databasePath;
..........................
}
app.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
databaseName = @"database.sqlite";
site_domain=@"http://localhost/webservice";
NSLog(@"%@",site_domain);
// inside this function I can use the value, ..if I call whatever function from
//this function, that function can also use the value...
}
-(void) functionTest {
NSLog(@"%@",site_domain);
//here the value is lost, it's like it can't reach it's pointer or something...
//puts on a wierd string
}
What am i Doing wrong?
Because you never take ownership of it, your string is getting autoreleased by the auto release pool. In your
didFinishLaunchingWithOptions:method, try using:And don’t forget to release it int the dealloc method