我正在试着写一本字典。下面的代码没有报告任何错误,但是我找不到我应该写的文件的任何踪迹。以下是代码片段:
NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"First letter of the alphabet", @"A",
@"Second letter of the alphabet", @"B",
@"Third letter of the alphabet", @"C",
nil
];无论使用哪种方法调用,我都可以看到正确显示的字典内容:
NSLog(@"Here is my partial dictionary %@", myDictionary);
for (NSString *key in myDictionary)
NSLog(@"here it is again %@ %@", key, [myDictionary objectForKey:key]);以下代码在程序重复运行时显示"succeeded“消息
if ([myDictionary writeToFile: @"myDictionary" atomically:YES ] == NO)
NSLog(@"write to file failed");
else
NSLog(@"write to file succeeded");即使以原子方式将:参数更改为NO也不会写入临时文件。然而,当我搜索我的当前目录,甚至我的整个Mac时,我找不到任何名为"myDictionary.plist“的文件或任何带有字符串"myDictionary”的文件。
path变量"@myDictionary“不是应该表示当前目录下的文件吗?
发布于 2011-03-15 17:01:47
您的代码告诉系统在文件上写入字典,但是在哪个文件上,文件位置的路径是什么?Alekkhya的代码做到了这一点,它在应用程序沙箱中定义了一个特定的目录(文档目录),获取该目录的路径并将文件写入其中。
我建议你读一下this。
https://stackoverflow.com/questions/5308958
复制相似问题