esea123
esea123

Reputation: 75

Xcode Swift: Could not insert new outlet connection

Im getting following error when I'm trying to connect outlet from my search bar. enter image description here

How can I solve that?

Upvotes: 4

Views: 8816

Answers (10)

Ario Liyan
Ario Liyan

Reputation: 345

This can be caused by couple of different reasons, I try to list them here:

  1. You are working on a modular application and the storyboard file can't find the ViewController file as its owner because the Module isn't selected from the identity inspector. enter image description here

in this case simply tick the inherit module from target(if your viewcontroller is within the same module) or chose the right module from the drop down mennu.

  1. You have a typo -> check if both the class name and the ViewController class definition matches and are the same.

  2. Xcode Derived data is corrupted and outdated. In this case open Xcode -> Preferences -> Locations -> Click the gray arrow by the Derived Data folder and delete your project folder.

  3. Sometimes there isn't any of the above problem and you can try readdressing the class in the interface builder then clean the project by pressing command + shift + K keys and restart the XCode.

  4. If none of the above worked, try to create an empty outlet in your ViewController file something like:

      @IBOutlet
      private var yourViewName: YourViewType!
    

and then click and drag the outlet to your view in the interface builder

Upvotes: 1

Guilherme Rangel
Guilherme Rangel

Reputation: 87

What worked for me was to make the call the other way around, example: @IBOutlet weak var imageView: UIImageView!

I connected the .swift file to the .storyboard

Upvotes: 0

novice
novice

Reputation: 451

I created two classes with the same name in the project which gave me this error. By deleting one class file the issue got resolved.

Upvotes: 0

Chea Thim
Chea Thim

Reputation: 1

Error? Just check the locations of UI class file(swift) and UI builder file(xib or storyboard). Best is "Relative to Group"

Upvotes: -3

Cons Bulaquena
Cons Bulaquena

Reputation: 2113

  1. Clean the Project

enter image description here

  1. Build and then Run.

  2. Try to add the outlets again, it will work this time.

Upvotes: 7

jrbm
jrbm

Reputation: 11

I know it's too late to answer this question. But, I think it was because you made a change to the class name on your swift file and it hasn't been saved yet. (The file is grayed out)

My solution: Try building it (Command + B), then connect it again.

Upvotes: 0

Mathias Van Houtte
Mathias Van Houtte

Reputation: 200

I had this issue and I searched for several days how to fix this. I tried every solution that I could find, but without any luck.

I started looking in my git history on which branch the error occurred. I found a solution after several days.

I was working on a big project and I wanted to speed up my build speed and I changed some stuff in the build settings. The build setting that caused this issue was 'Swift compiler - Optimization level'. I changed the default value (No optimization) to 'Optimize for speed' and this caused the issue "Could not insert new outlet connection".

I hope I can help others with this solution because I lost a lot of time with it.

This is what it should be

Upvotes: 5

Mujahid Latif
Mujahid Latif

Reputation: 616

In my case nothing worked

1) Deleting Class

2) Disconnecting the @IBOutlet

3) Manually Creating @IBOutlet Connections

The thing which did work was to restart XCode

After restart you can easily connect them without errors

Upvotes: 1

claude31
claude31

Reputation: 884

Can you connect the other way, ie from the IBOutlet to the search bar ? In such a case, a clean of build border plus a reopen of the project should solve the problem.

Upvotes: 0

Kathiresan Murugan
Kathiresan Murugan

Reputation: 2962

Check that ViewController is correct or not?

Or

Clear class name in storyboard and edit again and also in class file

Or

quit Xcode and reopen and try that

Upvotes: 0

Related Questions