If this is not too inefficient in order to immediately get the whole thing in memory, then the most compact sequence of calls (which I expanded to several lines for easier presentation):
NSError *error = nil; NSString *sourceString = [NSString stringWithContentsOfFile:@"..." encoding:NSUTF8StringEncoding error:&error]; NSArray *lines = [sourceString componentsSeparatedByCharactersInSet: [NSCharacterSet newlineCharacterSet]]; NSString *relevantLine = [lines objectAtIndex:1000];
You must check the error and count for lines to check.
EDIT: For comparison with Nathan's answer, the advantage of character separation in a set is that you accept any of the five Unicode characters that can delimit a line break anywhere where several of them sit next to each other counting only one gap (like e.g. \r\n ).
NSInputStream , you probably have to deal with the fact that the memory issue is a problem that barely evolves than C stdio.h fopen / fread / etc, so you have to write your own little loop to scroll.
source share