You can create an instance of NSTimer and have it, every X seconds, call another method that's responsible for reading the file and updating your progress bar. That method can use NSString's stringWithContentsOfFile:
to read the file into a string, then parse it appropriately.
For example:
// Create the invocation of the method to call
NSUInteger X = 2; // Change depending on how often you want the timer fired
NSMethodSignature *signature = [self methodSignatureForSelector:@selector(read)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
// Create the timer, adding it to the default run loop
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:X
invocation:invocation
repeats:YES];
And later, you define the selector read
:
- (void)read {
NSString *fileContents = [NSString stringWithContentsOfFile:@"aFile.txt"];
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
NSString *lastLine = [lines lastObject];
// Your own parsing and updating code here
}
If you need a definite stopping point, you can store timer
in an ivar inside your class, then call [timer invalidate];
whenever your parsing code inside read
determines you're done with whatever process you're executing.
Relevant docs: