如果我有以下内容,iOS上的NSSearchPathForDirectoriesInDomains何时会返回0路径:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"paths: %d", [paths count]);
if ([paths count] > 0)
{
// path exists and is the 1st item in the array
}
else
{
// path doesn't exist. Under what conditions would it not exist?
}
答案 0 :(得分:1)
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
添加“s”
答案 1 :(得分:1)
我怀疑这只是防御性编码。我不明白为什么那个确切的调用会返回0路径,但NSSearchPathForDirectoriesInDomains()方法可能会使用传递给它的不同参数。
另外,即使路径存在,文档也说不能保证实际的目录存在,所以理想情况下你也需要在那里做另一张检查,虽然对于NSDocumentDirectory我怀疑大多数人,包括我自己,只是假设它会在那里 - 不明白为什么它不会......
答案 2 :(得分:0)
我认为那里没有崩溃。只是编译器停在错误的位置。