How to check if a file exists in the Documents directory in Swift?
Swift
I am using [ .writeFilePath ] method to save an image into the Documents
[ .writeFilePath ]
Swift 4.2
extension URL { func checkFileExist() -> Bool { let path = self.path if (FileManager.default.fileExists(atPath: path)) { print("FILE AVAILABLE") return true }else { print("FILE NOT AVAILABLE") return false; } } }
Using: -
if fileUrl.checkFileExist() { // Do Something }