Created
October 21, 2009 09:13
-
-
Save sukima/214981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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