how to change view controllers through code on xcode swift

hello,

ok so im using story boards and swift. basically i hold CONTROL and drag from a button to my second view controller i made and click "present modally" option so now my second view controller shows once the button is clicked.

so my main question is.. i would like to close the second view controller that i opened through code so once my function has executed at the end i would like the close the second view controller screen and go back to the main view controller screen.

how is this done?

i am currently using this line of code on my logout function
Code Block
self.present( UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "mainPAGE") as UIViewController, animated: true, completion: nil)


so is there a way to close the opened view controller that was opened?

i am currently using this line of code on my logout function

What is your logout function?

You may need to clarify what view controllers are involved in the situation and name them.

once my function has executed

Please clarify what is your function.

so is there a way to close the opened view controller that was opened? 

I think there is. Why don't you use dismiss?


By the way, your question has nothing to do with the SwiftUI framework. Using the tag SwiftUI seems to be inappropriate.
how to change view controllers through code on xcode swift
 
 
Q