appendPathPath(_ :)之后的其他路径

时间:2018-08-31 14:23:32

标签: ios swift

我正在尝试访问复制到~/Documents文件夹中的json文件。

当我检查那里有哪些文件时,它会将这些文件放在一个数组中,其路径以file:///private/var/mobile/Containers/Data/Application/95982B17-2C5F-4E3F-8AD7-FB90F557B991/Documents/开头:

let fileManager = FileManager.default
       if let docDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first {
           do {
               let docs = try fileManager.contentsOfDirectory(at: docDirectory, includingPropertiesForKeys: [], options: .skipsHiddenFiles)
               print("Files in ~/Documents are: ")
               for doc in docs {
                   print(doc)
               }

           } catch let error {
               Logger.printLogEntry(message: "Could not get content of documents directory: \(error.localizedDescription)", category: .dev
               )
           }
       }

但是当我然后添加这样的路径

let filePath = docDirectory.appendingPathComponent("products.json")
print("File Path is: ", filePath)

它为我提供了以下路径:file:///var/mobile/Containers/Data/Application/95982B17-2C5F-4E3F-8AD7-FB90F557B991/Documents/

这在模拟器上有所不同;路径保持不变(前面没有private东西...

有人可以向我解释吗?需要明确的是,我需要使用不同的方法进行复制/访问,因此了解其不同访问方式对我来说至关重要。

1 个答案:

答案 0 :(得分:0)

因此,希望其他人在研究此问题时能够获得更大的成功: /var和/ private / var`指向真实设备上的同一文件夹,因为一个是另一个的别名,如上面的注释所述。因此,感谢评论者的提示。