How to connect ViewController.swift to ViewController in Storyboard?

  1. Choose your ViewController in the storyboard or scene list (mine is called Circuit).
  2. Click on the Identity Inspector on the right
  3. Select Custom Class > Class > Type name of your swift file.

DONE :)

Here are these two steps on image (ugly i know)


You have your ViewControler created with some Objects in it (UILabel, UIButton, UIImage...)

enter image description here

1 - You need to link your ViewControler in your story board to your ViewController.swift , to do this follow the pictures

enter image description here

2 - In the class filed put the name of the ViewController class. With that you just linked your storyBoard view controller to your viewController.swift class

Class = ViewController.swift

enter image description here

3 - Now you need to cretae the variables you want to asign(UILabel, UIButton ... that you have in your storyboard): in this example:

class MovieDetailViewController: UIViewController, DetailView {
    
    var presenter: MovieDetailPresenter!
    var movie: Movie?
    
    @IBOutlet weak var lblMovieYear: UILabel!
    @IBOutlet weak var lblMovieTitle: UILabel!
    @IBOutlet weak var movieImage: UIImageView!
    @IBOutlet weak var lblMovieRating: UILabel!
    @IBOutlet weak var lblMovieOverview: UILabel! 
}

4 - To link the UILabel in the story board to your UILabel variable or your UIButton in your story board to your UIButton var, follow the next images

First select the view controller in the storyboard

enter image description here

Second select the parragraf icon in the right up corner ands clicked 'Assistant', it will open a screen of your ViewControler.swift

enter image description here enter image description here

Now you just need to drag the variable to the corresponding object and you will be done.enter image description here

Remember to do this with all variables, you will need to create a variable for each object you have in the storyboard


Connect storyboard and view controller

You should set ViewController in Class` field

enter image description here