在 iOS 中有两种获取和创建目录路径的方法:
- (NSString *)documentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}
- (NSString *)dataFilePath
{
return [[self documentsDirectory] stringByAppendingPathComponent:@"Checklists.plist"];
}
然后要求 NSLog 将结果打印到调试器:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Documents folder is %@", [self documentsDirectory]);
NSLog(@"Data file path is %@", [self dataFilePath]);
}
调试器控制台中的结果是:
2013-01-09 13:23:10.845 Checklists[6734:c07] Documents folder is /Users/pdenlinger/Library/Application Support/iPhone Simulator/5.1/Applications/BBBA8972-3B38-4606-AECD-5D98821469D6/Documents
2013-01-09 13:23:10.847 Checklists[6734:c07] Data file path is /Users/pdenlinger/Library/Application Support/iPhone Simulator/5.1/Applications/BBBA8972-3B38-4606-AECD-5D98821469D6/Documents/Checklists.plist
问题是,当我在 Finder 中剪切并粘贴 Documents 文件夹的路径(使用Command + shift + G命令)时,Finder 返回的结果表明没有这样的目录。
已在终端中手动尝试过,结果相同。
该怎么办?
我正在使用 Xcode 4.5.2 运行 OS X 10.8.2