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?
Accepted Reply
I just renamed my ViewController class and now everything works just fine.
-
It works fine for me. Thanks.
-
it always works. Thank you.
Replies
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.
I just renamed my ViewController class and now everything works just fine.
-
It works fine for me. Thanks.
-
it always works. Thank you.
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:
- Delete the storyboard segue and/or outlets references
- Delete outlets in file ViewController.swift and copy the content file
- Delete this file (Select the option "Move to trash")
- Create the file again and put the content
- Connect the segue and/or outlets references again
Obs: Clean Build folder and Run
I have restarted the laptop and it starts working.
just delete the old view controller and replace with new and the same name that works perfectly....
I fix this issue add ViewController traditional mode with Cocoa Touch Class not Swift File