Is it possible to use NSThreads for parsing four different URLs using NSXMLParser
If I try to parse single HTTP URL, it will be done quic开发者_如何学编程kly. But if I have to parse four different URLs at application launch, is it feasible to use NSThreads and NSOperation queue. Can any one explain with a small example if possible?
Sagos
Write an NSOperation subclass, and in the main method, do something like this:
- (void)main
{
NSXMLParser *parser = [[[NSXMLParser alloc] initWithContentsOfURL:myURL_] autorelease];
[parser setDelegate:self];
[parser parse];
}
Implement your parser delegate methods on your NSOperation subclass. Then instantiate the subclasses, assign them the URLS, and add them to an operation queue. Use notifications or delegates to know when they are finished.
Yes. Do use NSOperationQueue. The following link basically shows how to parse multiple URL (xml files) using NSOperationQueue.
http://www.cocoabuilder.com/archive/cocoa/275115-nsoperationqueue-for-nsxmlparser-object.html
精彩评论