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]];

Add your voice!

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