Reputation: 75
Im getting following error when I'm trying to connect outlet from my search bar.
How can I solve that?
Upvotes: 4
Views: 8816
Reputation: 345
This can be caused by couple of different reasons, I try to list them 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.
You have a typo -> check if both the class name and the ViewController class definition matches and are the same.
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.
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.
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
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
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
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
Reputation: 2113
Build and then Run.
Try to add the outlets again, it will work this time.
Upvotes: 7
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
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.
Upvotes: 5
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
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
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