0
プロパティリストを取得する最善の方法は何ですか?メインバンドルとドキュメントディレクトリのplistファイルへのアクセス
1 - メインバンドルから、すなわち:
NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"];
2 - またはドキュメントディレクトリからのパスを取得する、すなわち:
// Data.plist code - get path from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our plist file.
NSString *plistPath = [documentsPath
stringByAppendingPathComponent:@"Data.plist"];
// check to see if Data.plist exists in documents
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) {
// if not in documents, get property list from main bundle
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
何、なぜ? 両方が正しい場合、なぜ1行のコードで最初のものを使用しないのですか?
さらに重要なことに、アプリケーションバンドルのファイルは、アプリケーションの一部としてパッケージ化されています。ドキュメントフォルダ内のファイルはランタイムイベントです。ファイルはアプリの一部として開始されません。 – rmaddy
あなたの素早い対応のために@vadianに感謝します。 –