views:

35

answers:

1

I've built a basic Web XML to Core Data parsing system, but I am confused about how to set off several parsers at once, and know when they are all done.

This is my current setup, which gets just one parsed xml file ("news"). But I have several xml files I need to parse ("sport", "shop" etc). How would set all of these off, and know when they are all done?

// ViewController.m

DataGrabber *dataGrabber = [[DataGrabber alloc] init];
dataGrabber.delegate = self;
[dataGrabber getData:@"news"];


// DataGrabber delegate method (within ViewController) which gets called when dataGrabber has got all of the XML file
- (void) dataGrabberFinished:(DataGrabber *)dataGrabber
{
   NSManagedObjectContext *context = [self managedObjectContext];
   NSError *parseError = nil;
   // Parser puts the xml into core data. Do I need delegate on this too?
   Parser *xmlParse = [[Parser alloc] initWithContext:context];
   [xmlParse parseXMLFileWithData:dataGrabber.payload parseError:&parseError];
   [xmlParse release];
}

(this a follow-on from this question - http://stackoverflow.com/questions/3883747/returning-data-from-data-grabbing-class-from-web )

+1  A: 

One option is to count how many you create and then have each one call back to a method that counts down from that total. When its back to zero they are all done.

You will need to set up a delegate for the parser just like you did for the downloader.

Ben