Updating label takes too long (swift)

4 Solutions Collect From Internet About “Updating label takes too long (swift)”

What happens is that code is probably run on a secondary thread. Any UI changes you make should be made on the main thread. So try this:

dispatch_async(dispatch_get_main_queue()) {
    // update label
}

This should update your label instantly.

Previously, we would choose the dispatch method (sync vs async) and then the queue we wanted to dispatch our task to. The updated GCD reverses this order – we first choose the queue and then apply a dispatch method.

Swift 3:

Now in Swift 3 the GCD library was updated like in the following way:

DispatchQueue.main.async(execute: {
    // UI Updates
})

I hope this help you.

It might be late to answer but in Swift 3 logic should be like this.

DispatchQueue.global(qos: .background).async {
// Background Thread Or Service call Or DB fetch etc
DispatchQueue.main.async {
    // Run UI Updates and other logic
}}

Your code has multiple issues.

FIRST: It has strong reference cycle

Fix it by putting this in closure.

 [weak weakSelf = self]

SECOND: Update UI in main thread

DispatchQueue.main.async {
 //Update UI
 weakSelf?.mReslut.text = ""
}