Beginning Core Data · Challenge: Fixing Sorting Issues |

This is a companion discussion topic for the original entry at

Using DispatchQueue.main.async{}
When is it necessary to update view elements in dispatchqueue.main.async and when not?
For eg.,
searchBar.text = nil
In the tutorial code, this was not inside main.async, is there any logic to know which code to run on DispatchQueue.main.async?

You always need to update all your view elements on the main thread. The UI elements aren’t thread-safe and will become corrupted if you attempt to update them from the background.

1 Like

Hi thanks for the response, watched the ios beginner courses. It was clarified there :slight_smile:

Awesome! Glad to hear you got clarification!