You can see the NSOperationQueue documentation page here .
There are also two existing stack overflow questions that are addressed using NSOperationQueue , which are here and here , Both have accepted the answers.
As for figuring out if the file was finished writing, I had this problem when I was writing an OS X application that created a very large file. I wanted the user to be able to track the progress of the recording. I ended up using NSTimer with UIProgressBar
Essentially, you will need to determine the (expected) total file size. Then, when you write the file, you should have another method (in the checkFileWritingProgress code checkFileWritingProgress ) that you can call at periodic intervals with NSTimer . Check the current progress against the total expected file size and update the UIProgressBar .
I have provided some code to get you started.
- (void)checkFileWritingProgress:(NSTimer *)someTimer { fileAttributes = [fileManager attributesOfItemAtPath:[NSString stringWithFormat:@"%@.data",saveLocation] error:nil]; currentFileSize = [fileAttributes fileSize]; // instance variable if(currentFileSize < maxFileSize) { // maxFileSize is instance variable [progressBar setDoubleValue:(((double)currentFileSize/(double)maxFileSize)*100)]; // progressWindows OS X only... not on iOS //[progressWindow setTitle:[NSString stringWithFormat:@"Writing... | %.0f%%",(((double)currentFileSize/(double)maxFileSize)*100)]]; } else { [progressBar setDoubleValue:100.0]; } }
And the timer ...
NSTimer *timer = [[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(checkFileWritingProgress:) userInfo:nil repeats:YES] retain];
Hope this code helps. Let me know if something needs to be clarified.
source share