Adding items to Swift array across multiple threads causing issues (because arrays aren't thread safe) - how do I get around that?

后端 未结 5 1033
南笙
南笙 2020-11-28 12:12

I want to add given blocks to an array, and then run all the blocks contained in the array, when requested. I have code similar to this:

class MyArrayBlockCl         


        
5条回答
  •  借酒劲吻你
    2020-11-28 12:41

    NSOperationQueue itself is thread safe, so you could set suspended to true, add all the blocks you want from any thread, and then set suspended to false to run all the blocks.

提交回复
热议问题