Created
November 7, 2013 18:34
-
-
Save krhoyt/7359586 to your computer and use it in GitHub Desktop.
Write a text file to disk.
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
- ( void ) writeTextFile : ( NSString * ) fileName withContents : ( NSString * ) contents | |
{ | |
NSArray * directories; | |
NSDate * now; | |
NSDateFormatter * formatter; | |
NSError * error; | |
NSFileManager * manager; | |
NSMutableString * append; | |
NSMutableString * path; | |
now = [NSDate date]; | |
formatter = [[NSDateFormatter alloc] init]; | |
[formatter setDateStyle:NSDateFormatterLongStyle]; | |
append = [[NSMutableString alloc] initWithString : contents]; | |
[append appendString: @"\r"]; | |
[append appendString :[formatter stringFromDate : now]]; | |
manager = [NSFileManager defaultManager]; | |
directories = NSSearchPathForDirectoriesInDomains( NSDesktopDirectory, NSUserDomainMask, YES ); | |
path = [[NSMutableString alloc] initWithString : [directories objectAtIndex : 0]]; | |
[path appendString: @"/"]; | |
[path appendString: fileName]; | |
[append writeToFile : path atomically : YES encoding : NSUTF8StringEncoding error : &error]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment