google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.79k stars 292 forks source link

How can I update the UI view information? #172

Closed cdwmhcc closed 3 years ago

cdwmhcc commented 3 years ago
func step1() -> Promise<String> {
        return Promise<String> { fulfill, reject in
             fulfill("confim")
        }
}
func step3() -> Promise<String> {
        return Promise<String> { fulfill, reject in
             fulfill("confim")
        }
}
func copyTask(timer:Timer) {
        DispatchQueue.global(qos: DispatchQoS.background.qosClass).async {
                self.cpSize = Double(self.currentCpSize)
                DispatchQueue.main.async {
                       self.progressBar.doubleValue = (self.cpSize * 100) / self.totalSize
                }
        }
}
step1().then{ result in
        let Timers = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) {
                timer in
                self.copyTask(timer: timer)
        }
}.then{ result in
        return self.step3(result)
}
....

The view can be updated when the Promise is not used, but when the Promise is used, it cannot update the view.

self.progressBar.doubleValue = (self.cpSize * 100) / self.totalSize