Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在swift中使用fileManager.unmountVolume_Swift_Macos_Nsfilemanager - Fatal编程技术网

如何在swift中使用fileManager.unmountVolume

如何在swift中使用fileManager.unmountVolume,swift,macos,nsfilemanager,Swift,Macos,Nsfilemanager,我正试图在swift中弹出/卸载usb驱动器 我想我必须使用fileManager.unmountVolume let urlString = "/Volumes/UNTITLED/".addingPercentEncoding(withAllowedCharacters: .urlUserAllowed) let url = URL(string: urlString!) fileManager.unmountVolume(at: url!, options: FileManager.Unm

我正试图在swift中弹出/卸载usb驱动器 我想我必须使用fileManager.unmountVolume

let urlString = "/Volumes/UNTITLED/".addingPercentEncoding(withAllowedCharacters: .urlUserAllowed)
let url = URL(string: urlString!)

fileManager.unmountVolume(at: url!, options: FileManager.UnmountOptions.init(), completionHandler: {(_) in})

wen没有插入驱动器我没有得到输出,但是wen插入驱动器我得到
cfurlcopyresourcepropertyWorkey失败,因为它被传递了一个没有方案的URL

urlString
不是URL字符串--它是文件系统路径。使用
URL(字符串:)
从中创建URL会导致URL不完整


改为使用创建
文件://
URL。(在将路径传递给此函数之前,不需要对路径进行百分比编码。)

谢谢,只是为了澄清此代码是否正确
fileManager.unmountVolume(位于:URL(fileURLWithPath:“/Volumes/UNTITLED”),选项:fileManager.UnmountOptions.init(),completionHandler:{(_)in})