Process Array in parallel using GCD

前端 未结 5 1319
青春惊慌失措
青春惊慌失措 2020-12-09 11:22

I have a large array that I would like to process by handing slices of it to a few asynchronous tasks. As a proof of concept, I have the written the following code:

5条回答
  •  时光取名叫无心
    2020-12-09 11:56

    You can also use concurrentPerform(iterations: Int, execute work: (Int) -> Swift.Void) (since Swift 3).

    It has a much simpler syntax and will wait for all threads to finalise before returning.:

    DispatchQueue.concurrentPerform(iterations: iterations) { i in
        performOperation(i)
    }
    

提交回复
热议问题