私はObjective-C初心者です。私はiPhoneプログラミングを勉強しています。私appDelegateでappDelegateメンバーにアクセスしようとするとiPhoneアプリがクラッシュする
は、-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法では、私はクラスのメンバ(@syntethizedは)DatabasePathにと呼ばれてきました。
私は、このようにその値を設定します。
databasePath = [self copyDatabaseToDocuments];
私はアラスデア・アーランで素晴らしい本から全体copyDatabaseToDocuments方法をコピーして(デシベルの名前は私が変更唯一のものです非常に小さな変更を加えました):
-(NSString *)copyDatabaseToDocuments{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath=[paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myDb.sqlite"];
//
if(![fileManager fileExistsAtPath:filePath]){
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myDb.sqlite"];
[fileManager copyItemAtPath:bundlePath toPath:filePath error:nil];
}
return filePath;
}
は私がDatabasePathにをのNSLogと私は定期的に割り当てた後(それは文字列のパスであり、それがnullではない)、その値を取得します。
次に、私は-(NSMutableArray*)readDatabase:(char*)querySQL
というメソッドを持っています。私はViewControllerからデリゲート参照を呼び出します。
この最後のメソッドが存在する場合は何も問題なく動作します。もう一度databasePathの値を割り当てます。
しかし、私はもう一度割り当てておらず、その値を使用したいのですが(それは-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
メソッドで設定されていると思います)、アプリケーションがクラッシュします。
なぜですか?
databasePathのヘッダーファイルに@propertyの定義を記述できますか? –