I saved image with this func:
let image = categoryImage.image
let data = image!.jpegData(compressionQuality: 0.5)!
let name = "\(Int(Date().timeIntervalSince1970))"
do {
let documentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:false)
let fileURL = documentDirectory.appendingPathComponent(name)
try data.write(to: fileURL)
print(fileURL)
} catch {
print(error.localizedDescription)
}
I get image from this:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CellPrototype
// Configure the cell...
let currentItem = item[indexPath.row]
cell.pointNameLabel.text = currentItem
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
if let dirPath = paths.first{
let imageURL = URL(fileURLWithPath: dirPath).appendingPathComponent("test")
let image = UIImage(contentsOfFile: imageURL.path)
cell.categoryImage.image = image
}
return cell
}
When i get image back i can't take it's name which was created by (Int(Date().timeIntervalSince1970))
How I can take specifically the file name that was created
When i take image name for example "test" image pass in cell
But in my app user select image and i don't know which image user selected