moe safar
moe safar

Reputation: 150

Unable to add IBOutlet in swift

I'm trying to add an IBOutlet in swift but I only have the option to add an action.

Here is an image of what I'm talking about.

enter image description here]

Is there any way I can fix this?

I can't change connection type either.

Upvotes: 2

Views: 1228

Answers (5)

user9535754
user9535754

Reputation:

You should use the same class in your view controller (call it View Controller.swift)

Upvotes: 0

celiux
celiux

Reputation: 623

This is happening because you are trying to connect an outlet from the Interface Builder to a non-corresponding View Controller file, so that's why it only gives you the option to add an Exit action. Just make sure that you are in the same View Controller both in the IB and in the Assistant Editor.

P.S. I recommend you renaming properly every view controller so it will be easier to avoid this (make sure to change the name not only in the class but also in the IB). You can use the cmd + click when selecting the class name on the code and click on Rename... to change all at once. If you already changed it in your code, you have also to do it then manually in the IB, selecting the corresponding one from the drop-down menu of the Identity Inspector:

enter image description here

Upvotes: 5

Waqas Sultan
Waqas Sultan

Reputation: 894

Simply change the connection type or one more thing you can do. you can do this. By opening connection inspector and drag the outlet into view controller like shown in image..

enter image description here

To Change Connection Type

enter image description here

Upvotes: 0

abhinikam
abhinikam

Reputation: 1

Restart your Xcode and try to connect @IBOutlet

Upvotes: 0

Harcker
Harcker

Reputation: 151

Try ctrl dragging it from the text on the left ()

Upvotes: 0

Related Questions