NSOperation and NSURLConnection mystified

后端 未结 3 916
谎友^
谎友^ 2021-01-22 14:37

I am trying to download multiple images from some server using NSOperation and NSOperationQueue. My main question is what is the difference between the code snippet below, and

3条回答
  •  甜味超标
    2021-01-22 15:22

    I prefer the second solution, because we have a lot more control over the operations

    If you refer to your own solution, then actually the opposite is the case:

    Due to the synchronous convenience method sendSynchronousRequest: you have basically no way to accomplish more practical requirements, like authentication, better error handling, and customized data handling, and many other features usually required in any app which is not a demo or toy app.

    The bummer however is the lack of the ability to cancel operations. You cannot cancel a block operation once it has started. And it's also not clear how you want to cancel the "for loop". So, once the loop is started you cannot stop it.

    You may want to search for more sophisticated (and more modern) approaches in the web and on SO.

提交回复
热议问题