ACBatchReader
ACBatchReader let's you read a plist
in a background process with periodic returns of batch data in the main thread.
Installation and usage
- Copy
ACBatchReader.h
andACBatchReader.m
to your Xcode project. - Create a new instance of
ACBatchReader
- Implement
ACBatchReaderDelegate
. - Set the batch size. (
batchSize
property) - Set the fileName (
setFileName:
) - Call
startReadingWithParser:
to start the background read. This method has a block as a parameter. This block receives a dictionary with the element just read from the file. This block needs to return an object or nil, if you don't want to add the current object to the results.
Examples
Set up:
self.batchReader = [[ACBatchReader alloc] init];
self.batchReader.debug = YES;
self.batchReader.delegate = self;
self.batchReader.batchSize = 1;
[self.batchReader setFileName:@"dummy-data"];
Start Parsing: If you want to filter some objects you can just return a nil object when you don't want that kind of result in your resulting array.
[self.batchReader startReadingWithParser:^id(NSDictionary *element) {
ACDummyContainer *dummy = [[ACDummyContainer alloc] init];
dummy.city = element[@"city"];
dummy.country = element[@"country"];
return dummy;
}];
- (void) batchRead:(NSArray *)batch{
//the size of this batch is the one set in the configuration.
[self.elementsRead addObjectsFromArray:batch];
}
- (void) batchFinished{
NSLog(@"Finished Background Task");
}
The result will be:
Version
1.0
License
MIT
Free Software, Hell Yeah!