Sometimes when I go to link my stoyboards to my view controller.swift, it doesn't link. Is there anything I'm doing wrong?

I go to link my label to viewcontroller.swift, but when I link it nothing in th code shows up (like an IBAction or a function). Is there a setting or anything I have to do?

Replies

It looks like you do not setup your ViewController class in Interface Builder.


Select your ViewController in Interface Builder and in the Identity inspector enter the class name.

Which version Xcode are you working with?


Not sure if this is your issue, but editing a viewcontroller's title can lead to this problem, in which case you should first, delete the viewcontroller and create a new one, then assign the new one to the storyboard where you want to make outlet.


Still no joy, follow ManuelMB's suggestion to confirm the class.

Ok, but how do I do this with a label?

You need to have the picture in mind:


- on one side you have a ViewController in IB, with objects as labels, buttons…

- on the other, you have your code in a class MyViewController (or any other name)


When you drag from a label in IB to the code, XCode will create an IBOutlet, that is to say a property in the class, connected to this IBOutlet.


But to do so, it needs to know that the ViewController in IB is effectively of the right class MyViewController.


You do so by selecting the ViewController in IB, open the Identity inspector (3rd icon or Inspectors panel) and type MyViewController in the class field of the custom class (default value to be replaced is UIViewController).


Now, you can connect objects in this view to code (IBOutlets or IBActions) in the class code.