ios - 在 iOS 上查找文档目录的替代方法

标签 ios

通常在 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/

相关文章:

ios - 无法更改 View Controller 属性的实例

ios - 如何使导航 Controller 导航栏不可见或至少改变颜色

objective-c - 如何调用encodeWithCoder

iphone - 增加/减少 UIImageView 的亮度

ios - 使用 Chipmunk 和 cocos2d 查找最近点

ios - 获取当前登录用户的 Sharepoint 用户详细信息? (SOAP API)

ios - ResearchKit 类前缀 "ORK"是什么的缩写?

ios - swift Realm : Thread Safe Concurrent Read and Write Index out of bounds

ios - 动画 UIView 就像它靠近或远离一样

ios - NSPredicate 一个关系对象