selez selez - 1 year ago 86
Swift Question

Updating label takes too long (swift)

I'm beginner swift developer. I'm stucked with this weather app.I'm downloading website data and then displaying in my label.

Unfortunately this whole process takes like 10 second to update my label.

This is probably not because of the network connection as the console is updated instantly.

Thanks for suggestions.

enter image description here

Answer Source

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.