How to connect ViewController.swift to ViewController in Storyboard?
- Choose your ViewController in the storyboard or scene list (mine is called
Circuit
). - Click on the
Identity Inspector
on the right - Select
Custom Class > Class > Type name of your swift file
.
DONE :)
You have your ViewControler
created with some Objects in it (UILabel
, UIButton
, UIImage
...)
1 - You need to link your ViewControler in your story board to your ViewController.swift
, to do this follow the pictures
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
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
Second select the parragraf icon in the right up corner ands clicked 'Assistant', it will open a screen of your ViewControler.swift
Now you just need to drag the variable to the corresponding object and you will be done.
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