@IBOutlet or @IBAction in your view controller first, then connect it to the storyboard or XIB object instead of having Xcode create the declaration. If that fails, check the scene’s custom class and target membership, then clean the build or restart Xcode.Why this happens
Xcode can show Could not insert new outlet connection: Could not find any information for the class named when Interface Builder cannot find enough information about a class to insert an outlet or action into its source file. The message appears while creating a connection between a storyboard or XIB object and Swift code.
The class assignment may be wrong, the Swift file may not belong to the app target, or Xcode’s project information may need to be refreshed. You do not necessarily need to delete files: a useful first workaround is to write the declaration yourself and connect it afterward.
How to fix it
1. Declare the outlet first, then connect it
Instead of dragging from Interface Builder into the editor to create a new declaration, add the property to the correct view controller yourself. For example, for a label in a storyboard:
import UIKit
final class ProfileViewController: UIViewController {
@IBOutlet weak var nameLabel: UILabel!
}
Use your existing controller name rather than adding a second class with the same name. Match the outlet type to the object you are connecting: use UIButton for a button, UILabel for a label, or NSLayoutConstraint for a constraint.
Then make the connection:
- Open the storyboard and select the scene that uses the controller.
- Open the Swift file alongside the storyboard.
- Find the empty connection circle in the editor gutter next to the outlet declaration.
- Drag from that circle to the matching object in the storyboard.
- Build and run the app to check that the connection works.
You can also select the object in Interface Builder and use its Connections inspector to make or inspect connections. If the outlet circle remains empty, the connection has not been established.
For an existing action, the same approach applies. Add a method such as:
@IBAction func didTapSave(_ sender: UIButton) {
print("Save tapped")
}
Place it inside your view controller class, then drag from its connection circle to the button and choose the appropriate event, such as Touch Up Inside. Declaring the property or method alone does not connect it to the interface.
For a XIB, make sure you are connecting the outlet to the object that owns it, such as File’s Owner when that is how the XIB is configured. The owner and custom class must match the code you intend to use.
2. Clean and build the project
If Xcode still cannot recognize the declaration or make the connection, clean the build and compile the project again:
- In Xcode, choose Product > Clean Build Folder.
- Choose Product > Build.
- Fix any build errors, then retry the connection.
A clean removes build products; it does not correct a misspelled class name or add a missing source file to a target. If the same message returns, check the scene and file configuration next.
3. Check the custom class and target membership
Interface Builder needs to associate the scene with the class containing the outlet. For a storyboard view controller:
- Select the view controller itself, rather than a label or button inside its view.
- Open the Identity inspector and check that Class names your Swift view controller.
- Check that the module is appropriate for the target containing the class.
- Select the Swift file in the project navigator and open the File inspector.
- Under Target Membership, confirm that the relevant app target is selected.
- Build again and retry the connection.
The class must contain the declaration you want to connect. For example, an outlet on ProfileViewController will not appear as an outlet on a different view controller merely because both scenes are in the same storyboard.
For a XIB, inspect the class of the relevant object or File’s Owner instead of assuming that the storyboard view-controller instructions apply unchanged.
4. Restart Xcode and clear the project’s Derived Data
If the class and target settings are correct but Xcode still cannot find the class information, first quit Xcode completely and reopen the project. Try the connection again before deleting anything.
If restarting does not help, remove the project’s Derived Data so Xcode can recreate it:
- Open Xcode settings and select Locations.
- Use the arrow next to the Derived Data location to open it in Finder.
- Quit Xcode.
- In Finder, find and delete the Derived Data folder for the affected project. Be careful not to delete the project source folder.
- Reopen the project, build it, and retry the connection.
The next build may take longer because Xcode must recreate build data. Clearing Derived Data is a troubleshooting step, not a replacement for fixing errors in the Swift file or storyboard configuration.
5. Re-add the Swift file reference
If the issue persists for one controller file, the source material also suggests removing and re-adding its project reference. Keep a backup or commit your changes first.
- Select the affected Swift file in the project navigator and delete it from the project.
- When prompted, choose Remove Reference, not Move to Trash. This keeps the source file on disk.
- Add the existing Swift file back to the project.
- Check its target membership in the File inspector.
- Build and try the connection again.
This is a later troubleshooting step because it changes the project configuration. Avoid adding a second copy of the class; re-add the existing file instead.
How to prevent it
- Set the correct custom class and module before connecting a storyboard scene or XIB owner.
- Check target membership when adding or moving a view controller file.
- Use an outlet type that matches the Interface Builder object.
- Build after changing project configuration, and fix compiler errors before troubleshooting connections.
- Inspect existing connections when renaming or removing outlets and actions.
FAQ
Why does manually adding an IBOutlet help?
It avoids asking Xcode to insert the Swift declaration during the drag operation. You still need to connect the declared outlet to the interface object afterward.
Does cleaning the build delete my storyboard or Swift files?
No. Cleaning removes build products, not your project source files. Similarly, the project’s Derived Data is separate from the source folder, but check the folder location carefully before deleting anything.
What if the app crashes because an outlet is nil?
Check that the outlet is connected in the storyboard or XIB actually used at runtime, and that its owner has the correct class. Also access view-controller outlets after the view has loaded, such as in viewDidLoad, rather than during the controller’s initialization.
Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.