Avatar
norio_nomura 3/8/2018 12:09 AM
https://talk.objc.io/episodes/S01E90-concurrent-map に出てきたconcurrentMap extension Array { func concurrentMap<B>(_ transform: @escaping (Element) -> B) -> [B] { var result = Array<B?>(repeating: nil, count: count) let q = DispatchQueue(label: "sync queue") DispatchQueue.concurrentPerform(iterations: count) { idx in let element = self[idx] let transformed = transform(element) q.sync { result[idx] = transformed } } return result.map { $0! } } } これq.sync {}を使う必要なかったりしないのかな? 間違った実装を引用していたのを修正 (edited)
We implement a concurrent version of the map method for arrays.