Question

I am loading a huge amount of data from an XML file. This data is "freezing" the application. I would like to display a progress bar in the time that the data is being loaded.

How would I know that much of the operation has been completed so that I can change the percentage shown of the progress bar? Thanks. [answered]

Edited: The main problem is that the application freezes during loading due to the large amount of data to be parsed. Some have suggested using a background thread to load and parse the data.. Is that viable?

Was it helpful?

Solution

Read the file into memory @ 4k at a time? Show the process of loaded bytes vs file size?

Additionally figure out total number of lines and what current line your parser is on.

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/occ/instm/NSXMLParser/lineNumber

Assuming you are using NSXMLParser

The "freezing" is coming from you doing the load/parsing on the main thread. If you can us GCD trying doing a dispatch_async ( ) and sending updates to your main thread on completion and to update progress.

OTHER TIPS

If you are using NSXML parser,

NSUInteger count = [[rootElement nodesForXPath:@"//Video" error:&error] count];
//this will give you the number of elements
//then after parsing each element, calculate the percentage of elements parsed. 

//i.e. num_of_elements_parsed/total_no_elements*100;
//based on this value, use a del;egate method to update your NSProgressIndicator 
// in this method increment the  num_of_elements_parsed counter
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {

    if ([elementName isEqualToString:@"resident"]) {

        self.count += 1; 

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top