Hi, I am struggling with the correct design for the delegates of nsxmlparser.
In order to build my table of Foos, I need to make two types of webservice calls; one for the whole table and one for each row. It's essentially a master-query then detail-query, except the master-query-result-xml doesn't return enough information so i then need to query the detail for each row. I'm not dealing with enormous amounts of data.
Anyway - previously I've just used
NSXMLParser *parser = [[NSXMLParser alloc]init];
[parser setDelegate:self];
[parser parse];
and implemented all the appropriate delegate methods in whatever class i'm in.
In attempt at cleanliness, I've now created two separate delegate classes and done something like:
NSXMLParser *xp = [[NSXMLParser alloc]init];
MyMasterXMLParserDelegate *masterParserDelegate = [[MyMasterXMLParser]alloc]init];
[xp setDelegate:masterParserDelegate];
[xp parse];
In addition to being cleaner (in my opinion, at least), it also means each of the -parser:didStartElement
implementations don't spend most of the time trying to figure out which xml they're parsing.
So now the real crux of the problem.
Before i split out the delegates, i had in the main class that was also implementing the delegate methods, a class-level NSMutableArray that I would just put my objects-created-from-xml in when -parser:didEndElement
found the 'end' of each record.
Now the delegates are in separate classes, I can't figure out how to have the -parser:didEndElement in the 'detail' delegate class "return" the created object to the calling class. At least, not in a clean OO way. I'm sure i could do it with all sorts of nasty class methods.
Does the question make sense? Thanks.