Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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
进程发生时,ios视觉效果不更新。(Swift 3)_Ios_Swift_Multithreading_Swift3 - Fatal编程技术网

进程发生时,ios视觉效果不更新。(Swift 3)

进程发生时,ios视觉效果不更新。(Swift 3),ios,swift,multithreading,swift3,Ios,Swift,Multithreading,Swift3,我有一个过程需要一些时间来处理: for n in 0..<currentAmount { if gcd(random(max: Int(randRange.value)), random(max: Int(randRange.value))) == 1{ gcdCounter += 1 } piProgress.setProgress(Float(Double(n)/Double(currentAmount)), animated: false)

我有一个过程需要一些时间来处理:

for n in 0..<currentAmount {
    if gcd(random(max: Int(randRange.value)), random(max: Int(randRange.value))) == 1{
        gcdCounter += 1
    }
    piProgress.setProgress(Float(Double(n)/Double(currentAmount)), animated: false)
}
我可以在控制台中很好地看到进度,那么为什么视图没有更新呢?我读到它与进程运行在哪个线程上有关,但我认为这是在objective-c中,而不是Swift 3中。请帮忙。我喜欢看到我的应用程序做一些事情


编辑:在浏览之后,我发现这个资源对于学习GCD非常有用:

,因为所有的UI更新,例如对任何UILabel、UIButton等的更新都必须在主线程上完成,即DispatchQueue.main.async{self.myLabel.text=“progress is now\(pc)%”


在主线程之外完成任务很好,但必须在主线程上更新UI。这包括任何影响自动布局的内容。

线程规则与语言无关。您链接的另一个问题同样适用于您的案例。我不理解其中编写的任何代码,是吗尽管有一些规则可以用另一种语言发布,但我认为这对其他任何想找和我一样东西的人来说都是有用的。
print(Float(Double(n)/Double(currentAmount))