Year3000
Year3000

Reputation: 459

RaptureXML kind of slow

I've recently switched from TBXML to RaptureXML, and even though pulling in information is much easier, there is a noticeable delay when I tap the tab bar button containing my xml table view.

In my viewDidLoad method I have the following"

events = [[NSMutableArray alloc] init];

[self loadURL];

And my loadURL method is the following:

- (void)loadURL {

RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://api.somexml.com/xml"]];

[rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) {
    [events addObject:[NSArray arrayWithObjects:
                       [event attribute:@"uri"],
                       [event attribute:@"displayName"],
                       [event attribute:@"type"],
                       nil]];  
}];

[rootXML iterateWithRootXPath:@"//location" usingBlock: ^(RXMLElement *location) {
    [events addObject:[NSArray arrayWithObjects:
                       [location attribute:@"city"],
                       [location attribute:@"lat"],
                       [location attribute:@"lng"],
                       nil]]; 
}];

[rootXML iterateWithRootXPath:@"//start" usingBlock:^(RXMLElement *start) {
    [events addObject:[NSArray arrayWithObjects:
                       [start attribute:@"time"],
                       [start attribute:@"date"],
                       nil]]; 
}];



}

Is there something I can do to speed it up? Also when I assign my row count as [events count] I'm getting 19 rows when I should only get 6. Please help.

Upvotes: 0

Views: 705

Answers (1)

sudo rm -rf
sudo rm -rf

Reputation: 29524

Till is on the right track. You need to parse on a background thread. Do something like the following:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [self loadURL];

    dispatch_async(dispatch_get_main_queue(), ^{
        [tableView reloadData];
    });
});

You'll notice that I'm reloading the tableview on the main thread. Updating interface elements on a background thread is a bit no-no.

Upvotes: 2

Related Questions