How to check file exists in Swift

October 13, 2017

In iOS app development you need to check the existence of file in your device
You can use the following code to check the existence of the file

// First create a FileManager instance

let fileManager = NSFileManager.defaultManager()

// Now you can check the existence by giving the path 

if fileManager.fileExistsAtPath("hello.swift") {
    print("File exists")
} else {
    print("File not found")