iOS - How to know when NSOperationQueue finish processing a few operations?

前端 未结 4 717
我寻月下人不归
我寻月下人不归 2020-12-04 23:01

I need in my application to download directories and their content. So I decided to implement a NSOperationQueue and I subclassed NSOperation to implement NSURLRequest etc..

4条回答
  •  情歌与酒
    2020-12-04 23:41

    You can refactor your code to avoid enqueuing all requests at once. Enqueue only requests for a single directory at a time. When operationCount reaches zero, you can be sure that all the requests either completed or failed, update the UI and enqueue the requests for the next directory. Proceed until the array of directories is empty.

    The advantages are:

    • relative simplicity
    • you don't have to query the file system only to figure out what has been downloaded
    • if need be, you can re-enqueue failed requests without changing other logic.

提交回复
热议问题