Problem

When we adding outlet connection from story board to code in assistant editor ,sometimes we get this error:

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

Environment

  • XCode 11.3.1

  • Swift 5

Reason

This is mostly caused by the refactoring of your code, for example, if you renamed the viewcontroller , you would probobably encounter this error: Could not insert new outlet connection: Could not find a class named ViewController in the language Swift.

Solution

Way #1

Click the menu: Product – Clean build folder

After clean, please click Product – Build, and then retry to add the outlet connection.

Way #2

Restart the xcode, and then retry to add the outlet connection.

Way #3

If all the above methods fail, please try to rename the viewcontroller again, this might help.