後でアプリに書き込む plist ファイルを作成しようとしています。最初の viewDidLoad で、次のメソッドを呼び出します
-(void)createFavoritesFile{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
if (![fileManager fileExistsAtPath:documentDBFolderPath])
{
NSLog(@"file doesnt exist");
NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"data.plist"];
[fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error];
}
else{
NSLog(@"file exists");
}
}
ただし、アプリを実行するたびに、作成されたファイルが見つからず、アプリを閉じて再度開くと、NSLog はファイルが存在しないことを示します。何か不足していますか?