WechatIMG326.jpeg
@objc func saveFile(_ data: NSData, name: String, allowedFileTypes: [String] = ["jpg","png"]) {
let panel = NSSavePanel()
panel.title = "保存文件"
panel.message = "请选择文件保存地址"
panel.directoryURL = URL(string: "\(NSHomeDirectory())/Downloads")
panel.nameFieldStringValue = name
panel.allowsOtherFileTypes = true
panel.allowedFileTypes = allowedFileTypes
panel.isExtensionHidden = false
panel.canCreateDirectories = true
panel.begin { (response) in
if response == .OK {
if let path = panel.url?.path {
data.write(toFile: path, atomically: true)
}
}
}
}
网友评论