Logging by Appending to a File
suggest changeNSLog writes to the console. You can also append to a file. This assumes self is an NSString, and that path and enc (NSStringEncoding) are already defined:
NSFileHandle* fh = [NSFileHandle fileHandleForWritingAtPath:path];
if ( !fh ) {
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
fh = [NSFileHandle fileHandleForWritingAtPath:path];
}
if ( fh ) {
@try {
[fh seekToEndOfFile];
[fh writeData:[self dataUsingEncoding:enc]];
}
@catch (NSException *exception) {
}
[fh closeFile];
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents