gpt4 book ai didi

ios - 没有那个文件或目录,NSFilePath=~/Library

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:37 24 4
gpt4 key购买 nike

当我运行下面的代码片段时会抛出下面引用的错误

fileManager.contentsOfDirectoryAtPath(libraryPath)

错误

Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x17585bf0 {NSUnderlyingError=0x175706b0 "The operation couldn’t be completed. No such file or directory", NSFilePath=~/Library, NSUserStringVariant=( Folder )}

这是我使用的完整代码片段,以防万一有人想尝试

   func listLibDir(){

let libraryPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, false).first!

let fileManager: NSFileManager = NSFileManager.defaultManager()

do{
var directoryContent:Array<String> = try fileManager.contentsOfDirectoryAtPath(libraryPath)

for fileName: String in directoryContent {
print("library:\(fileName)")
}
}
catch{
print(error)
}

}

如果有人能澄清为什么会发生此错误并提出解决方案,那就太好了

最佳答案

在您的代码中:

let libraryPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, false).first!

将权限设置为true:

let libraryPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, true).first

关于ios - 没有那个文件或目录,NSFilePath=~/Library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34948857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com