Hi,
I want to log my log strings to a file.
I implemented the following method:
void QuietLog (NSString *format, ...) {
if (format == nil) {
printf("nil\n");
return;
}
va_list argList;
va_start(argList, format);
NSMutableString *s = [[NSMutableString alloc] initWithFormat:format
arguments:argList];
[s replaceOccurrencesOfString: @"%%"
withString: @"%%%%"
options: 0
range: NSMakeRange(0, [s length])];
#ifdef LOGTOFILE_MODE
NSData *dataToWrite = [s dataUsingEncoding: NSUTF8StringEncoding];
[dataToWrite writeToFile: Log_FilePath atomically: YES];
#else
printf("%s\n", [s UTF8String]);
#endif
[s release];
va_end(argList);
}
The writeToFile method replaces all the data that was in a file before with the last string. But I'd like to keep the previously added data and add to it a new string.
What is the problem with writeToFile? Why does it overwrites all existing data? How can I add new strings instead of overwriting the old ones?
Thanks.