How to test if a file exists

- by

Imagine we had a file that we’ve saved:

NSString *myFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/myFile.txt"];

Before accessing it we can determine if it exists or not:

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSHomeDirectory()stringByAppendingPathComponent:myFile]];


If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.