I can't add an outlet to my code from storyboard.

I am a beginner in Xcode, and am just trying to make a sample app to learn the ropes. Over the last few days I have had a few issues. Every time I try to open assistant editor from storyboard, it takes me to a file called 'UIViewController.h.' I checked the top bar, and it is set to automatic. There is no manual option when I click on it either. On top of this, when I try to manually splitscreen ViewController.swift and ctrl-drag from my object to the editor, it doesn't let me add an outlet, and is stuck on 'action.' When I try to change the class for my view controller in identity inspector, it doesn't let me type in my class, which is 'ViewController.swift.' I even tried deleting the DerivedData folder, which was recommended by another forum, which didn't help. I really don't know what to do here, given that I have exhausted every resource on google's front page regarding this issue.


I edit you post for better readability.

But first: which version of XCode ?


Every time I try to open assistant editor from storyboard, it takes me to a file called 'UIViewController.h.' I checked the top bar, and it is set to automatic. There is no manual option when I click on it either.

Do you see the option "Top level objects" menu when you click in the icon with 4 squares at top left of the bar ?
This is active if the viewController is selected in IB
Select the ViewController.swift after holding option key: that will open it in another pane.

On top of this, when I try to manually splitscreen ViewController.swift and ctrl-drag from my object to the editor, it doesn't let me add an outlet, and is stuck on 'action.'


Where do you ctrl-drag in the swift file ?
Have you checked that the ViewController in IB is of the right class ?


When I try to change the class for my view controller in identity inspector, it doesn't let me type in my class, which is 'ViewController.swift.'

Class is not ViewController.swift (that's the file) ; class is what you defined in
Code Block
class ViewController: UIViewController {


I even tried deleting the DerivedData folder, which was recommended by another forum, which didn't help.

That was good to try, but no effect if class definitions in IB are not correct.
I am using Xcode 11.6.

When I look at top level objects in the 4 squares on the top left, it shows me 2 files: UIViewController.h, and UISwipeGestureRecognizer.h

I ctrl-drag to the ViewController.swift file, which is opened in splitscreen. I don't know how to check whether it is in the right class, what does that mean?

I'm a beginner, so I don't really get what I am doing here. Thanks for trying to help though.

I ctrl-drag to the ViewController.swift file, which is opened in splitscreen. I don't know how to check whether it is in the right class, what does that mean?

Can you show the name of the class ?
It is in a statement like
Code Block
class ViewController: UIViewController { }
inside ViewController.swift

Then look at the Identity inspector for the ViewController in Interface Builder.
  • Select the ViewController window by clicking on its top part where you have a few colored icons

  • Open the inspectors and look for Identity Inspector (should be the 4th icon)

  • At top of Identity inspector, you have Custom Class area.

  • Type ViewController (or the exact name of class inside) and hit return

Once this is done, try again to connect an IBOutlet
From what type of object in IB you try to ctrl-drag to the swift file ?
I can't add an outlet to my code from storyboard.
 
 
Q