3

I need to parse some files in the background mode. How can I do this. Is it NSXMLParser asynchronous?

bryanmac
  • 38,941
  • 11
  • 91
  • 99
Voloda2
  • 12,359
  • 18
  • 80
  • 130

3 Answers3

3

It is not async, but you can always run the parse in another thread using this:

+ (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • SO you are saying that we can't parse at the same time on different threads, but we can queue several parsing operations on a single unique background thread? – Plot Mar 10 '15 at 17:15
2

You could use GCD dispatch queues or Operation Queues to run the parsing in the background.

https://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html

Blocks are fun :)

bryanmac
  • 38,941
  • 11
  • 91
  • 99
0

If ios is 4.0+, then you can put NSXMLParser in another class and make the class to be the delegate of your current view controller. It will run at different thread and won't block your main thread.

Raymond Wang
  • 1,484
  • 2
  • 18
  • 33