In the .h i’ve declared:
// in database.h
@interface database : UIViewController {
NSString* databaseName;
NSString* databasePath;
}
On execution, methodA is called first , which I get the databasePath to point to my database.db file:
//methodA: in database.m
- (void)methodA {
databaseName = @"database.db";
NSArray* documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDir = [documentsPath objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
NSFileManager* filemagar = [NSFileManager defaultManager];
NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
[filemagar copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
NSLog (@"databasePath is...%@", databasePath);
[filemagar release];
}
The databasePath will return a string of folder path name “/Users/….”. So this is what I need.
Now subsequently, when I call method B…:
//methodB: in database.m
- (void)methodB {
NSLog (@"databasePath is now...%@", databasePath);
}
The program terminates as databasePath that is pointing to previous method strings, is no longer the same.
How do I retain the databasePath info , so that I can use in the other methods later?
This line:
Should be:
Another way to do this would be to use properties:
Then in your
@implementation: