我保存在一个文件目录下的文件中迅速3验证码:将文件保存在swift 3文件目录中?
fileManager = FileManager.default
// let documentDirectory = fileManager?.urls(for: .documentDirectory, in: .userDomainMask).first as String
var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
path = path + name
let image = #imageLiteral(resourceName: "Notifications")
let imageData = UIImageJPEGRepresentation(image, 0.5)
let bool = fileManager?.createFile(atPath: path, contents: imageData, attributes: nil)
print("bool is \(bool)")
return true
但正如你所看到的,我没有使用filemanager
获取文档目录路径filemanager
只给出网址不串。
问题:
- 如何从文件管理器串?
- 有没有在我的代码崩溃的机会?
'让文件管理器= FileManager.default.urls(为:.documentDirectory在:.userDomainMask)。首先? .path' – WeiJay