単純な配列を plist ファイルに書き込んでから、後で取得しようとしています。次のコードがあります。
+ (NSString*) dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *dataFilePath = [documentDirectory stringByAppendingPathComponent:@"TipAlertViewDefaults.plist"];
return dataFilePath;
}
+ (NSArray*) tipAlertViewDefaults
{
NSString *dataFilePath = [self dataFilePath];
NSLog(@"DataFilePath: %@", dataFilePath);
NSMutableArray *tipAlertViewDefaults;
if ([[NSFileManager defaultManager] fileExistsAtPath:dataFilePath])
{
NSLog(@"File Exists");
tipAlertViewDefaults = [[NSMutableArray alloc] initWithContentsOfFile:dataFilePath];
}
else
{
NSLog(@"File Doesn't Exist");
tipAlertViewDefaults = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithBool:NO], nil];
[tipAlertViewDefaults writeToFile:dataFilePath atomically:YES];
}
return tipAlertViewDefaults;
}
このメソッドを 2 回呼び出します。1 回目は、ファイルを見つけて初めて書き込むべきではありません。2 番目の呼び出しでファイルを見つけることができるはずですが、そうではありません。ここで私が間違っているところを誰かが見ることができますか?