"Could not find any information for class named ViewController"
Asked Answered
I

42

170

This bug has been driving me nuts since I started using Xcode (4.6.3). Whenever I try to link a Storyboard item to my code, I get the error:

Could not find any information for class named ViewController.

This happens with custom classes as well. I've tried methods such as:

  • Deleting the delegate data.
  • Removing and re-adding the classes.
  • Restarting Xcode.
  • Reinstalling Xcode.

I can't ctrl-drag to create connections in any of my projects no matter what the class is. The same problem happens with a brand-new template application. If I type in the code manually and then ctrl-drag, I can make a working connection, but I can't add it automatically. Nothing I've been able to find so far on the Internet has helped. Any pointers?

Integrant answered 18/7, 2013 at 22:37 Comment(6)
Are you triple sure that the ViewController .m file is included in the proper target? (checkbox in the righthand inspector panel)Embarrassment
You have a view controller in your storyboard and specified "ViewController" for the name of the class that should be instantiated to manage the view. Check each view controller in the storyboard: select the view controller, look at the "identity inspector" on the right-hand pane, and look at the "Custom Class" property. If it reads "ViewController" then there's your problem. Put in the name of the class that should manage your view controller... or put in UIViewController to get the default UIKit implementation.Normandnormandy
I changed the custom class to "UIViewController" in the identity inspector, and was no longer able to ctrl-drag from the storyboard into ViewController.h. If I create a new class and try to ctrl-drag into it (after setting the view controller's class accordingly), I get the same "Could not find any information" error.Integrant
I had this problem, and modifying the auto-generated ViewController class worked for me. E.g. just add an NSLog() to viewDidLoad:Bogosian
Possible duplicate of Could not insert new outlet connection: Could not find any information for the class namedSadesadella
In my case, I had created a View Controller named "aaa", removed the reference but did not delete. I meant to delete as well as remove reference. So I went to the file system and deleted the file there. Then I recreated a new View Controller with the same name. I did wonder if there would be a left over problem that was not obvious to me as I'm new to Swift. I ended up doing a Build->Clean and then restarted XCode ("open myproject.xcworkspace). Then I was able to drag the outlet without error.Convexoconcave
B
320

What solved this issue for me was actually deleting the class from the project.

Steps:

  1. In the project file explorer (left panel) find the class and right click -> Delete
  2. Remove reference (do not move to trash as you will lose the class for good)
  3. Right click on the folder that contained the class -> Add files to ...
  4. Find the class you just deleted in the file system

This seems to force Xcode to link the class back into the storyboard.

Note: for me the following did not work:

  • Closing Xcode
  • Cleaning the project
  • Deleting the class name from the storyboard and re-entering it

I think this is a bug on Apple's part

Beaconsfield answered 20/12, 2014 at 9:2 Comment(11)
I also tried what is listed in this answer as not working. I also renamed the VC to something else and tried again. Still no luck.Jejune
@Michael, Yes, now I'm in a situation where none of the above works at all. Xcode is a ***Beaconsfield
also make sure your file is in the correct folder. i've placed mine in the same folder as the appdelegate.swift fileAlten
Thank you, this worked for me too. Xcode v 7.0.1. I deleted the references to both the .h and the .m files, then added them again.Vestiary
This issue dates back to Jul 2013, as of today May 2016 I get the same bug and fixed it with this answer. How come in so many years Apple doesn't fix it for good?Northnortheast
2017 (Version 8.2 (8C38)) and still alive, Xcode SUCKS. It happens to me when you copy-paste UI staff from the storyboard from one scene to anotherMcgill
worked for me! Things that did not work: 1. clean 2. blow away derived data 3. close and reopen 4. remove/readd class name in IB 5. typing @IBOutlet var ... and manually linking 6. creating a new file and copy and pasting the class 7. general raging at my laptop, xcode, apple, tim cook, etcGoshawk
April 19th 2018, still have this stupid bug in Xcode 9.3. Unbelievable, I'm wondering how Apple uses my 99$ per year.Eady
Xcode 10 beta 5, still an issue (I had to join in, this was too funny scrolling through and seeing every version of Xcode)Slight
I deleted the class completely, added it back as a new file and then tried connecting. Worked for me. Then I just added the code back manually. This worked for me. I am on XCode 11.Seersucker
This issue still persists in 2021, Xcode 13.1. You still have to delete the file(not the reference, the actual file) and create a new file with whatever name and hook it up with Storyboard..Rabbin
D
145

In case anyone is still frustrated by this, there's a trick to get things working.

What I do is manually enter an outlet into my class, for example: @IBOutlet weak var someView: UIView!, and drag from the code to the view in IB or storyboard. After this, I am able to drag from IB / Storyboard to my class to make connections, assistant editors recognizes the class in "Automatic", etc...

Works every time.

Disembark answered 6/4, 2015 at 15:59 Comment(11)
@Gmeister4, if you create an outlet in your code it shows a small circle to the left of the outlet. Click and drag from that circle to the view in IB or Storyboard to make your connection.Disembark
Ah I see. Didnt realise you could do that. Thanks!Chloric
Still can't do it the proper way around, not even after this - but at least this works!Steiermark
After writing @IBOutlet in code I was able to drag to this outlet from Storyboard (not to small circle but to blue square that appears)Oaken
It's 2017, Xcode 9.0.1 and this answer was helpful. It also needed to be done once, all next outlets can be connected with mouse. What's worse, it is possible that all other answers are equally good, but we have to pick one working in particular configuration.Questioning
It has to be one of the most annoying "little" bugs I've encountered. It's just habit now to perform the above whenever Xcode forgets how to behave.Disembark
Tried to restart and didn't work, then added manually entered like above and didnt work. Restarted again and it worked!!Marcus
still a bug in 2018, this fixed it. Filing a radar with Apple, this is ridiculous.Cupidity
Sometimes it feels like Xcode do not know what to do :| but I am glad that you know what to do (Y)Chokefull
It's so annoying that Xcode constantly seems to be working against you. How can this "IDE" still be so horrible!?Dilation
Still persist on 2023 with Xcode 15.0.1, this answer fix the problem.Aviary
B
43

For me removing them from your target membership in the right column and adding them again did the trick enter image description here

Bobbitt answered 10/11, 2015 at 2:44 Comment(5)
This also worked from me. I had duplicated the ViewController.swift class, and this seems to be the solution.Echinus
I think it's a bug of Xcode which still exist in Xcode 8.0Rack
This happened right now to me in Xcode 8.3.3 and your solution is the simplest and works. So thank you!!!Niehaus
Still exist in Xcode 11.5 (I mean seriously Apple??). Only solution which worked for me listed here.Teerell
Works on Xcode 14.2Heydon
C
13

Sometime Xcode does due to VC not referencing class file. The simple solution for this is:

write property manually as given.

class YourClassName{

     @IBOutlet weak var YourTableName: UITableView!

}

This will make a empty link sign before @IBOutlet, open your project in assistant editor then click link sign enter image description here and drag into the View which you want to connect (i have connected with TableView). and thats it. Enjoy Happy Coding!!!

Czech answered 17/1, 2017 at 8:59 Comment(0)
I
8

I tried everything and it didn't work, so for me what worked is:

  • Clean Build folder and project.
  • Open Projects (Window -> Projects)
  • Find your project on the list and delete the Derived Data
  • Close Xcode
  • Restart computer (without choosing to reopen windows that are open)
  • run Xcode
  • Work!

All my view controllers were not being recognized, so deleting all files and re-adding was not an option as this is a big project.

Isolative answered 9/3, 2016 at 16:51 Comment(0)
K
8

I just had this problem on April 2017 with Xcode 8

Simply creating an outlet through code and compiling fixed it. eg:

@IBOutlet weak var containerViewHeight: NSLayoutConstraint!

You got to love Xcode…

Edit: Still happening on Xcode 9

Kohn answered 13/4, 2017 at 13:10 Comment(0)
F
7

the following steps works for me hope that works for you also

1- You need to reopen you project after closing Xcode.

2- Wait for indexing project files

3- Check if it work or not

4- If still not working follow step 5, if not happy for you :)

5- Clean and Build your project target

enter image description here

Flora answered 19/8, 2016 at 15:27 Comment(0)
A
4

I had to do a combination of a couple of the answers so far:

  1. Remove the custom class name from the storyboard.

(Click the yellow button at the top left of the view controller in the storyboard -> go to the identity inspector (option + command + 3) -> delete the custom class name at the top)

  1. Remove the reference to the view controller file.

(Right-click the file -> delete -> remove reference)

  1. Add the view controller file back to the project.

(Right click the folder where the file was -> "Add file to [project]")

  1. Add the custom class name back to the storyboard.
Antelope answered 29/4, 2015 at 15:18 Comment(0)
H
4

For me, the following worked:

  1. Do a 'clean' and a 'clean build folder' (press 'option' on the Product menu to get the 'clean build folder' command

  2. Stop Xcode

  3. In terminal, go to the derived data folder:

    (/Users//Library/Developer/Xcode/DerivedData)

Delete the derived data dir for your project.

  1. Wave dead chicken in the air

  2. Start Xcode

Headless answered 20/9, 2017 at 13:45 Comment(0)
J
3

If people try the above and things are still not working, the strange trick that worked for me was adding the outlet in a chunk of whitespace. It works if there are no other lines directly above or below the line you're adding. Strange, but it worked!

Jounce answered 21/6, 2016 at 15:42 Comment(0)
R
3

What worked for me was, instead of dragging the connection from the button to the code, was:

  1. Clicking the desired storyboard item.
  2. Opening the connection inspector (right panel)
  3. Dragging from the + circle to the area of code. Like so:

after I linked my code in this way, it worked normally from thereafter.

Raneeraney answered 7/4, 2017 at 15:43 Comment(0)
B
3

Stay On Target!

I was adding a new class with a Xib and I started seeing this issue and I spent a goodly time looking through the answers on here and seeing if any of it made a difference to it.

As it happens, I have multiple targets in my workspace and often I have to switch between them.

Turns out adding new files will kick start a re-index in Xcode. But if you are pointing at the wrong target then the indexing is likely to meaningless and during the drag to connect Xcode will not be able to find your class.

In short

Step 1.

Target Seledction

Make sure you have the correct target set so that indexing makes sense.

Britney answered 3/7, 2018 at 14:17 Comment(0)
R
3

This worked for me:

  1. Perform 'Clean build folder'
    (press and hold the 'option' key and go to the "Product" menu to access it.
  2. Perform a simple "Clean" (CMD-SHIFT-K) from the "Product" menu.
  3. Build the project to let Xcode compile the files. Also, let it index files if necessary.

On a side note, I am not sure if this helped but I also deleted the Derived data before performing the above steps (Xcode preferences > Locations)

Recipience answered 6/7, 2018 at 12:17 Comment(0)
K
2

Select the ViewController in storyBoard, delete current value in Right hand panel/"Customer class"/"class" then re-add control class (type: "SampleViewController"...), enter. --> That work for me

Karyogamy answered 5/9, 2014 at 7:20 Comment(0)
F
2

I tried all of these answers, the problem for me was related to Xcode not being able to index the files. I fixed this by simply quitting Xcode and reopening the project. Of course I did that after trying all of the above solutions :p

Flurried answered 25/10, 2015 at 16:11 Comment(0)
R
2

Product > Clean (Command - Shift - K) fixed it for me!

Radferd answered 16/9, 2016 at 19:36 Comment(0)
C
2

This is the EASIEST step that I did to fix this problem.

  1. I clean the project
  2. Drag a new button in the view controller.
  3. Build the project.
  4. Connect the newly dragged the button to the class (either outlet or action).
  5. Then voila!!! Other outlets can now be connected to the class again!
Considerable answered 14/9, 2017 at 2:4 Comment(0)
N
1

As my testing experience,if you delete a class which was associated in the Xcode,and than add file again,than this issue will occur.

Niphablepsia answered 1/4, 2016 at 8:26 Comment(0)
H
1

Usually when this happens to me I just haven't saved the code for the class yet. Just hop over to the code and hit cmd+s and it often fixes the problem right way.

Hardball answered 17/11, 2016 at 20:58 Comment(0)
H
1

Okay guys saw almost all top answers and none worked for me.

So what worked for me is the following:

  1. Copy the Derived Data address from your Xcode project. This can be done using the following:

Xcode -> Preferences -> Location Tab -> Derived Data

  1. Close Xcode

  2. Now go to the derived data location and delete the folder of your project there.

Now open Xcode and voila!

Hyperphysical answered 29/11, 2016 at 11:31 Comment(0)
R
1

Just need to clean and re-build the project.

Romanic answered 27/12, 2017 at 21:15 Comment(0)
A
1

None of the steps above worked for me, but I think I may have discovered the issue. At least it is what worked for me, and it is not a bug in Xcode.

When in the assistant editor look at the top of the window that has the code for your viewController. The third option from the right likely says "Manual", but it should say "Automatic". Once I changed this, the problem was resolved!

Alexandra answered 12/1, 2018 at 1:8 Comment(0)
L
1

I just restart Xcode and then it works.

Letishaletitia answered 25/5, 2018 at 7:6 Comment(0)
P
1

I was getting a similar problem, "Could not find a class named..." and the cause was stupid on my part once I figured it out. Make sure you aren't dragging from the item to the interface - make sure it's being dragged to the class itself

Pampuch answered 29/8, 2018 at 19:33 Comment(0)
G
1

I tried EVERYTHING!

Make sure the class name of your UIViewController does not contain the word "Test"

Bug Report submitted.

Grados answered 2/9, 2018 at 22:12 Comment(2)
Definitely not saying that this is the only cause. Just that this is another thing to be aware of.Grados
Help for me delete all derived data, clean project. But this is bug and you are right.Gotama
I
0

I would try to remake the .m and .h files in question and give them an original name, not generic like "ViewController". Try something more along the lines of what you want that file to do, and ending in View Controller (i.e. "PizzaDecoraterViewController")

Then select the ViewController that you want to connect to those files. Make sure that you select the ViewController, not just an object within. Click the black bar at the bottom (the one that has the "First Responder" and "Exit" icons). The entire ViewController should outline blue. Then go to the Custom Class section in the Identity Inspector and you should see a grayed out "UIViewController" in the first field. In that field, type in the name of the .h or .m file that you want it to connect to (Start typing PizzaDecorator... and it should do a little auto-complete thing). Then hit ENTER.

When you open up the Assistant Editor, make sure that the file that you are trying to drag and drop to is, in fact, the correct file.

If you have done all as said above, then it should work.

Indraft answered 19/7, 2013 at 2:40 Comment(7)
Still doesn't work, unfortunately. I've tried to do this before to no avail. Here's a screenshot: i.imgur.com/5ixtcps.pngIntegrant
Huh. Strange. Try adding them in programmatically (i.e. @property (nonatomic, strong) IBOutlet UIView *test;) and then when the little circle appears next to it, drag and drop to your UIView.Indraft
That works and always has (and the apps seem to run okay), but I'm trying to solve the problem that it won't add automatically.Integrant
Well, if it works like that, then it should work the other way. Bug in your XCode? Try to get a previous version (like 4.6.2 or something) and install that. Otherwise, ummmmmmmmmmmmmmm...... yeah....Indraft
Yeah, that's what I'm afraid of. Uninstalling and reinstalling hasn't been working, I was hoping I was making a mistake. What's the best way to downgrade my copy of Xcode?Integrant
@Integrant Sorry for the wait, but Apple seems to have a web page down for their xcode downloads. Normally, you would just go to this page and click the "View Downloads". There you should see various versions of XCode, just download and install accordingly.Indraft
Just had the same happen for me in Xcode 5. Never seen this before. Tried dragging an IBOutlet into the viewController header and got that message. Restarting Xcode worked for me. Why, I have no idea.Cop
J
0

As I commented on @ChrisHarrison's answer, those things did not work for me, but deleting the derived data as in I got it to work by deleting the derived data as in https://mcmap.net/q/111755/-could-not-insert-new-outlet-connection-duplicate

Jejune answered 16/1, 2015 at 0:38 Comment(1)
Deleting derived data or cleaning rebuilding project or closing xcode did not work for me. I just created new viewcontroller class then copied- pasted old one but not class name included. so it started to work.Clarion
C
0

Delete the files (only the references) and add the files again.

Complex answered 26/8, 2015 at 10:19 Comment(0)
H
0

Well in my case, the thing that worked (it's a litle weird, but worked) is the following:

Try to add a datasource (ex. an extension to the ViewController like a UITableViewDataSource). Xcode will try to reload the ViewController. Then I wrote some method of the protocol (in the beginning Xcode did not autocomplete the methods, but wrote it out manually), then I added the IBOutlets, and then lastly, I removed the datasource.

Example:

class TestViewController:UIViewController{
    // This viewController presents “Could not find any information for  class named ViewController”
}

extension TestViewController:UITableViewDataSource{
    //Add Some methods of the protocol, Xcode will try to autocomplete and then it's going to reload the class, from then you can add your IBOulets / Actions .. And remove this extension if you don't need it otherwise.
}
Halhalafian answered 7/9, 2015 at 16:0 Comment(0)
P
0

For me, the view I had specified a custom class for was failing to be compiled by interface builder. It was marked @IBDesignable.

Removing @IBDesignable, and then adding my outlets, and then marking it as @IBDesignable resolved the issue in my case.

Procambium answered 8/10, 2015 at 19:22 Comment(0)
M
0

Just try to delete Derived Data for the project

Monophony answered 31/10, 2015 at 15:42 Comment(0)
C
0

just try this

rm -rf ~/Library/Caches/com.apple.dt.Xcode
defaults delete com.apple.dt.Xcode IDEIndexDisable
defaults write com.apple.dt.Xcode IDEIndexEnable 1 
Crackerjack answered 27/7, 2016 at 3:31 Comment(0)
B
0

Check from finder Xcode whether closed or not.

Force quit Xcode and restart.

Product > Clean

Boehmenism answered 12/10, 2016 at 7:5 Comment(0)
J
0

In my case, it was because the Xcode indexing process had stopped running. Rebooting my Mac fixed it.

Jurisdiction answered 27/10, 2016 at 12:35 Comment(0)
P
0

Go to the project folder and delete derived data folder

if you cant find the derived data, go to finder and go to

 ~/Library/Developer/XCode/DerivedData/"project"

(replace "project" name with project name)

Pinnatifid answered 6/4, 2018 at 10:59 Comment(0)
G
0

I know this is in most cases just Xcode acting out, but in my case none of the suggested actions managed to fix the issue and I believe it was a mistake I made when trying to rename my project, so I ended up creating a new project and importing everything over.

This eventually fixed it.

Genitor answered 20/6, 2019 at 9:45 Comment(0)
P
0

In my case I had a same class name and xcode could not recognize which one I am targeting so be careful in selecting name of your classes.

Polytypic answered 22/6, 2019 at 5:25 Comment(0)
A
0

What I did was to connect a button as an action with no arguments and sender as UIButton. The result was-

@IBAction func comma1() {

}

and I could put the rest of the outlets or actions.

Anschauung answered 22/11, 2019 at 14:40 Comment(0)
F
0

For me the issue was that there is a syntax error on the project. Everything worked fine after solving the error. I am working with xCode 11

Frivolous answered 21/3, 2020 at 15:39 Comment(0)
S
0

I got this problem after I applied the MVC architecture, after I changed the location of the info.plist file.

After specifying the new file location, the problem was resolved

Shithead answered 16/11, 2021 at 14:53 Comment(0)
H
0

Xcode Storyboard error

Could not insert new outlet connection: Could not find any information for the class named <controller_name>

This error also is occurred when you rename Main.storyboard(e.g. to Foo.storyboard) and try to connect storyboard with controller

To fix it just set correct name in Info.plist UISceneStoryboardFile string (in out case - Foo)

Helaine answered 14/8, 2023 at 13:19 Comment(0)
H
-1

You know what worked for me...

I save the application, closed Xcode and then re-opened the project file... good to go!

Humphreys answered 19/2 at 2:35 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Doretha

© 2022 - 2024 — McMap. All rights reserved.