Just a quick post announcing that I have open-sourced an Objective-C class that will read line-by-line from a file. In, and of, itself this isn’t too difficult, but I’ve also added the ability to tail the file (ala tail -f
) and also to handle the situation where the file gets renamed and a new file (with the same name as the original) gets written to.
An example of how to use is as follows:
BDFileTailer *tailer = [[BDFileTailer alloc] initWithURL:url]; tailer.shouldTail = YES; NSString *line = [tailer readLine]; while (line != nil) { NSLog(@"Line: %@", line); line = [self.tailer readLine]; }
Feel free to check it out from github, fork it, or feedback with issues.