• Step 1)
    Create a new singleView Xcode project.

    Step 2)
    Open Main.storyboard and drag and add a second view controller.

    Step 3)
    For the second view controller on Main.storyboard create a new COCOA TOUCH CLASSS (set to be a subclass of: UIViewController and Language: Swift) file with a name SecondViewController.

    Make sure it is a subclass of UIViewController and set its Identity->Storyboard ID to SecondViewController.

    Step 4)
    We want to pass a String value from one View Controller to another when user taps on a button. Let’s create a button first.  

    Step 5)
    Open Main.storyboard and select first ViewController and from the Objects library drag and drop UIButton and UITextField on the View

    Step 6)
    Open Assistant Editor and "control drag" from the button to the ViewController in Assistant editor to create an Action for the Button (named "firstButton").

    Step 7)
    While Assistant Editor is open, "control drag" to create an outlet for UITextField with a name myInfoText

    Step 8)
    Embed first ViewController into Navigation Controller, by selecting the first ViewController on the Main.storyboard and then from the top menu select Editor -> Embed in -> Navigation Controller.

    The Navigation Controller will let us have the Back button which we can use to go back from SecondViewController to first ViewController.

    Now when user taps on our button a function with a name firstButton will be called.

    Step 9)
    We want to pass to our SecondViewController a String value, so this is what we will do.

    Inside of Second View Controller:

    Create a property of type String with a name myStringValue

    Step 10)
    To keep this example simple we will simply print the value of myStringValue property inside the viewWillAppear function. The viewWillAppear function will be called automatically every time when SecondViewController is about to appear on the screen.

    Here is how my SecondViewController now looks:

     2ndView

    Step 11)
    Inside of firstButton function which is in first ViewController:


    We will write code to check if myTextField is not empty

    Create an instance of SecondViewController and set the value of its variable myStringValue to the value from myTextField

    And finally we will Present(push) SecondViewController to user.

    Here is how my first ViewController Add the following IBAction & code after the didReceiveMemoryWarning() function:

    1stButton

    Step 12)
    Finish the first ViewController with the new code between the curly braces after the return you alrady put into the button action:

     

    firstViewCont

     

    Step 13)
    Now run your application, type something into UITextField and tap on a button to see how it works. If the text field is not empty, user will be taken to a SecondViewController and the value set to myStringValue will be printed out to Debug area.