Running a View Controller in background of another View Controller

Hello!

I am trying to build an app that fetches information from the web in background and updates the fields in current View Controller.

For fetching information I need to log into the website, redirect to pages within and then fetch the required information. I am using WebView (and its evaluateJavaScript function) for doing this task. This information then should update the current View Controller which until then should show the previous information.

I wish to make the WebView functionality to execute in background while the user sees the previous information until the task is completed and then sees the updated information while (user) all the time being on the same View Controller.

I was able to make the WebView View Controller not show anything by not assigning the view of the View Controller to the webView.

How do I execute the WebView (currently a View Controller) functionality in the background of another View Controller?

take a look at DispatchQueue.main.async
this will run your code inside the closure in your main thread asynchronously