I want to quickly check to see if a file exists in my iPhone app's Documents directory (or any path for that matter). I can enumerate through the directory's files, or I can try to open a specific file. What's the fastest way? I just need to know if the file is there or if it does not exist.
Asked
Active
Viewed 2.3k times
94
1 Answers
193
Swift v3:
let fileExists = FileManager.default.fileExists(atPath: somePath)
Thanks to Nikolay Suvandzhiev.
Objective-C (Original):
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];
-
2Swift 3: `let fileExists = FileManager.default.fileExists(atPath: somePath)` – Nikolay Suvandzhiev Jul 14 '17 at 09:19