Q:

Swift - How to change view programmatically after validating from outside server

I have a login view page that should transition to a tab view controller once the login has been verified. However, I get an error instantiating the view within the session.dataTask
[24249:381955] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior.

Which results in a
terminating with uncaught exception of type NSException

How can I validate the user and bring him to the main page after validating from a server?

A:

It's because you shouldn't perform that operation on a background thread.
Move your instantiation code into main thread
DispatchQueue.main.async { 
// view instantition here.
}

