Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect ViewController.swift to ViewController in Storyboard?

I made a new view controller in Storyboard and made a new .Swift file that inherits UIViewController. However, my viewDidLoad() is not being called.

What do I need to do to connect my view controller in my story board to my .swift code so viewDidLoad() is called?

I see there's this: How to connect storyboard to viewcontroller

However, in a default project, FirstViewController(storyboard) doesn't have FirstViewController in that box, it is empty, yet viewDidLoad() is still called. It doesn't make sense.

like image 230
user83039 Avatar asked Oct 11 '14 04:10

user83039


People also ask

Can you combine SwiftUI with storyboard?

Open the storyboard and add a Container View to the View Controller where you want the SwiftUI View to appear. This Container View will then add an additional View Controller which is linked to the Container via an Embed Segue.

How do I connect my storyboard to SwiftUI?

Embedding the SwiftUI view into your storyboard is super simple, just follow the three steps below: Step 1: Inside your storyboard file click on the + button and drag and drop a Hosting View Controller. This View Controller is capable of hosting a SwiftUI view.


1 Answers

  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)

like image 75
Lachtan Avatar answered Sep 20 '22 16:09

Lachtan