Could not insert new outlet connection: Could not find a class named ViewController in the language Swift

I want to insert a new outlet for a stack view, but every time I click connedt, this error appears: "Could not insert new outlet connection: Could not find a classs named ViewController in the language Swift". I tried to clear the project and reopened it, but nothing changed. In my other projects it works just fine. I think the only thing I did was updating Xcode in the AppStore. Is it a problem with Xcode or can I do anything to fix this error?

Answered by De Mo in 338457022

I just renamed my ViewController class and now everything works just fine.

Probably, you have a UIViewController class (that you named as ViewController).


There is a ViewController in Interface Builder, but it does not know it is a ViewController.


Proceed as follows:

- select the UIViewController in IB

- Open Identity Inspector (3rd icon in Inspector panel)

- In the class field at the top, type ViewController (instead of placeholder UIViewController).


You should now be able to connect your outlet.


Note: it is good practice to give a more significant namle to the class ViewController, like MySweetViewController 🙂


To do this,

- open the file ViewController.Swift

- select ViewController in the class definition

- Ctril click on it to open a popup menu

- select Refactor > Rename

- type the new name and return


- you can also rename the file in the project navigator to be consistent.

- do a clean build folder (Product menu) if you rename the file

There was no placeholder UIBiewController, because it was already ViewController in the class field. Storyboard ID and Restoration ID are empty. I don't know if that's a Problem, but I was not able to connect the outlet.

Accepted Answer

I just renamed my ViewController class and now everything works just fine.

You could probably also do a Clean Build Folder to solve the problem. That was probably done when you changed the name, if you changed it with refactoring.

I observed the same problem.

https://forums.developer.apple.com/thread/105867


I observed that in that case, the file path reference at the top of the view controller is incomplete.


Instead of the full :

Project > Product > Controller > ClassName > selection

it shows only

ClassName > selection

Just renaming the file didn't work for me. What I did was:

  1. Delete the storyboard segue and/or outlets references
  2. Delete outlets in file ViewController.swift and copy the content file
  3. Delete this file (Select the option "Move to trash")
  4. Create the file again and put the content
  5. Connect the segue and/or outlets references again

Obs: Clean Build folder and Run

I have restarted the laptop and it starts working.

I fix this issue add ViewController traditional mode with Cocoa Touch Class not Swift File

just delete the old view controller and replace with new and the same name that works perfectly....

Had this problem with a blank dialog I had just created. The problem was that I renamed 'dialog.m' to 'dialog.mm' before making a connection. It resolved when I changed the name back to 'dialog.m'. Once a connection was made, I renamed the file again to 'dialog.mm' and could make new connections without problems.

Could not insert new outlet connection: Could not find a class named ViewController in the language Swift
 
 
Q