Logging by Appending to a File

suggest change

NSLog is good, but you can also log by appending to a file instead, using code like:

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 (...) {
    }
    [fh closeFile];
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Logging:
*Logging by Appending to a File

Table Of Contents