1.获取沙盒路径
let docPath = File.getUserFilePath()
class File {
//获取用户路径
static func getUserFilePath()->URL{
let manager = FileManager.default
let urlForDocument = manager.urls(for: .documentDirectory, in:.userDomainMask)
let url = urlForDocument[0] as URL
return url
}
}
2.添加文件路径及名称
//tempUrl = "img/#.jpg"
let file = docPath.appendingPathComponent(tempUrl)
3.把文件读取为二进制,并把转换为图片格式
let imgData = try! Data.init(contentsOf: file)
cell.image.image = UIImage(data: imgData)