Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift-强制同步执行工作和后续UI呈现_Swift_Multithreading_Synchronous - Fatal编程技术网

Swift-强制同步执行工作和后续UI呈现

Swift-强制同步执行工作和后续UI呈现,swift,multithreading,synchronous,Swift,Multithreading,Synchronous,我有一段遵循工作流的代码: for index in 0..<self!.recordedData.count { //Do work here that involves fetching data from coredata and prerendering an image for each index } reloadUIWithData() 通过以下方式: DispatchQueue.background(delay: 0.01, background: { for index

我有一段遵循工作流的代码:

for index in 0..<self!.recordedData.count {
//Do work here that involves fetching data from coredata and prerendering an image for each index
}
reloadUIWithData()
通过以下方式:

DispatchQueue.background(delay: 0.01, background: {
for index in 0..<self!.recordedData.count {
    //Do work here that involves fetching data from coredata and rendering an image for each index
    }
}, completion:{
reloadUIWithData()
}
DispatchQueue.background(延迟:0.01,背景:{

对于0..中的索引,有一个专用的API
DispatchGroup
来执行此操作。但是它不会使异步任务同步。它就像一个计数器,在
enter
上递增,在
leave
上递减,并在
notify
上通知循环中的所有任务完成时(计数器==0)

let group=DispatchGroup()

对于0..中的索引,有一个专用的API
DispatchGroup
来执行此操作。但是它不会使异步任务同步。它就像一个计数器,在
enter
上递增,在
leave
上递减,并在
notify
上通知循环中的所有任务完成时(计数器==0)

let group=DispatchGroup()
对于0中的索引。。
DispatchQueue.background(delay: 0.01, background: {
for index in 0..<self!.recordedData.count {
    //Do work here that involves fetching data from coredata and rendering an image for each index
    }
}, completion:{
reloadUIWithData()
}
let group = DispatchGroup()
for index in 0..<self!.recordedData.count {
    group.enter()
    doAsynchronousStuff { result in
        // do something with result
        group.leave()
    }
}
group.notify(queue: DispatchQueue.main) {
    self.reloadUIWithData()
}