문제

I am having some doubts about which is the best way to solve this problem.

In my app I have to parse xml from ~20 different urls. I want to put the logic inside of an NSOperationQueue, so I can split the task of synchronising in smaller tasks that I can add to the queue. Since this task have to connect to an url and I am using AFNetworking, how should I do it?

|
|
|------- => Start my OwnXMLOperation
|       |
|       |
|       | -------  => Start the AFNetworking operation inside my OwnXMLOperation
|       |        |
|       x        |
|                | => Download finish, starting the parser inside the success block
|                |
|------- => Anot | her OwnXMLOperation starts without the previous one is finished. 
|       |        |
|       |        |
|       |--------|--------
|       |        |        |
|       x        x => The | parser of the first operation finished.
|                         |
|                         |------- => Start the AFNetworking operation inside my OwnXMLOperation

How can I avoid this ugly NSOperation map? I was thinking about overriding an AFNetworking operation, what I don't even know if it is possible.

Thanks in advance

도움이 되었습니까?

해결책

Don't both with your own XML operation, the AFNetworking operations and queue can provide all of the queue management you require.

To keep things tidy, put your XML parsing into a number of methods (either in the controller class or a/several helper classes if you wish). Then you can call these methods as appropriate from the AFNetworking success blocks.

Be sure to set the maximum concurrent count on the queue if you're going to add 20 operations so you don't flood the network with requests.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top