Skip to content

Instantly share code, notes, and snippets.

@sukima
Created October 21, 2009 09:13
Show Gist options
  • Save sukima/214981 to your computer and use it in GitHub Desktop.
Save sukima/214981 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
void checkIfFileExist(NSString *path)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
if ( [fileManager fileExistsAtPath:path] )
NSLog(@"File exists!");
else
NSLog(@"File is missing!!!!");
}
int main(void)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// init dummy data
NSArray *array = [[NSArray alloc]
initWithObjects:@"test1", @"test2", @"test3", nil];
// Find the filename and path of the test file.
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *testDataPath = [documentsPath
stringByAppendingPathComponent:@"testData.plist"];
// Check if file exists
checkIfFileExist(testDataPath);
// Write out the file
[array writeToFile:testDataPath atomically:YES];
// Check if file exists again
checkIfFileExist(testDataPath);
// Clean up and exit
[array release];
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment