通常在 iOS 上查找文档目录的答案涉及如下代码:
+ (NSString *) applicationDocumentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
return basePath;
}
但是,我发现了一个替代版本:
+ (NSString *)applicationDocumentsDirectory
{
return [@"~/Documents" stringByExpandingTildeInPath];
}
有什么原因导致我不能使用这个吗?也许Documents目录将来可能不在主目录中?
最佳答案
Is there any reason why I can't use this? Perhaps the Documents directory may not be in the home directory in the future?
我想你在这里回答了你自己的问题。
第一种方法询问操作系统 Documents 目录在哪里,并且不做任何假设。
第二种方法假定文档目录的位置。
关于ios - 在 iOS 上查找文档目录的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10726701/