How to test if a file exists

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




Leave a Reply