639

I upgraded to Xcode 6 beta 4 and now my App continuously crashes with the message

Unknown class X in Interface Builder file.

It crashes because supposedly Xcode can't find my custom classes that I have linked in my Storyboard but it shows that they are linked correctly in the Xcode interface.

I'm positive everything is linked correctly. My only other option may be to delete the entire storyboard file and start from scratch because it might be corrupted somehow.

Edit: I would also like to add that I tried cleaning, reseting simulator, messing with build phases etc. None of that works.

6
  • Possible duplicate of stackoverflow.com/questions/3416269/…
    – Bouke
    Jul 24, 2014 at 5:20
  • 1
    @ImreKelényi You are right. This happened to me again recently after doing what you just described.
    – Epic Byte
    Aug 22, 2014 at 18:59
  • This worked for me, stackoverflow.com/questions/1725881/…
    – vrunoa
    May 12, 2015 at 22:34
  • It was typo for me, debug it to the Control element, till when it comes, select; View Controller > identity inspector > Custom Class > Class. delete that if that class is not defined.
    – mavericks
    Sep 30, 2015 at 9:50
  • 10
    PLEASE NOTE! This "error" can stem from different origins. If the accepted answer does not work for you then move down and try the next answer. The correct answer for my situation was the 5th answer.
    – Jacksonkr
    Feb 10, 2016 at 16:31

52 Answers 52

1511

I resolved this issue as I was typing the question. I figured I'd answer my question and leave it here for anyone else who may face this issue when using Xcode 6 beta 4.

To resolve this issue, you need to select each of your custom class objects in Storyboard (this includes any custom views, even the custom view controllers themselves).

Then with those objects selected, open the identity inspector and under "Custom Class" you should see the Module option. Finally:

  • Click inside the Module text box, and press enter.
  • Or (update 2022), check the "Inherit Module From Target" option.

That's it! The current module for all of my custom objects must have been internally incorrectly set somehow in Xcode 6 beta 4. But there was no visual indication of this in the inspector.

Note that if pressing enter inside the Module text box doesn't work, try selecting the arrow to the right and manually select your current module, then clear the text box and press enter. You can also try pressing enter inside the class text box (although this usually is to resolve a different issue).

Here is an image to make things more clear: enter image description here

43
  • 71
    For me, clicking inside "Module" and pressing enter did not work consistently, but selecting the "Class" field (and pressing enter) always did the job. Aug 22, 2014 at 14:54
  • 2
    For me, the target was set correctly, but the class still didn't show up in IB. I noticed, though, that the "Location" of the file showed a path "Relative to Project" instead of "Relative to Group". Removing the file reference AND the group and re-adding it in the project root worked for me.
    – knl
    Oct 20, 2014 at 20:14
  • 8
    Wow. Thanks for this, I don't think I would have got there otherwise. This fixed an issue that started happening after I added @objc(...) to one of my Swift classes. Nov 7, 2014 at 21:57
  • 13
    This issue is still present in XCode 7.2. This solution worked.
    – Tom Fast
    Dec 17, 2015 at 17:39
  • 3
    This is still an issue in Xcode 8.3.1... such a shame Apr 9, 2017 at 12:48
102

Sometimes Xcode missed customModule="AppName" customModuleProvider="target"

To fix it, open storyboard as source code and replace this line:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
sceneMemberID="viewController">

to this:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass"
 customModule="AppName" customModuleProvider="target" sceneMemberID="viewController">
12
  • 7
    Actually in my case i had to remove customModuleProvider, then the error went away. Mar 11, 2015 at 13:15
  • 3
    Guillermo, still happening in Xcode as of end of March!
    – Ed Manners
    Mar 27, 2015 at 15:30
  • 3
    @MaciejSwic Removing the customModuleProvider did it for me as well, thank you!
    – Sakiboy
    Apr 1, 2015 at 2:20
  • 1
    what about for xib files? Apr 27, 2015 at 21:59
  • 7
    Still happening... it's things like this that make me want to cry :(
    – Luke
    May 4, 2015 at 22:47
73

I had this problem after renaming a swift class. Solved it by using the @objc directive:

@objc(ForumTopicListViewController) class ForumTopicListViewController
9
  • 4
    This fixed it for me, I had @objc class X and changing to @objc(X) class X worked.
    – Joe
    Oct 29, 2014 at 13:25
  • 1
    You can also try to delete your derived data see stackoverflow.com/questions/24039932/… Dec 6, 2014 at 15:58
  • Had this problem after renaming the default ViewController class from the Single View project template. I wonder what magic was used so that the @objc() directive was not needed for the 'original' ViewController class... Dec 11, 2014 at 23:59
  • I goes the opposite side. I had specified the module name in Storyboard file but also added @objc directive.
    – WeZZard
    Jan 15, 2015 at 6:14
  • 1
    Did NOT work for me. :( Neither is the solution of Module name working. Nov 5, 2016 at 13:20
70

Project with Multiple Targets

In my case I am working on Project with multiple Targets and the issue was "inherit from Target" was unchecked. Selecting "inherit from target" solved my problem

enter image description here

3
  • Thanks for posting this. Solved the issue I was seeing very quickly.
    – JaredH
    Apr 26, 2018 at 1:50
  • I had a similar situation. (XCode 9.4.1) I created an iOS app called FilesTestA, with a custom UIView called MxFileView (which consisted of MxFileView.swift and MxFileView.xib). Then I added another target: a Today widget ("FilesTestAWidget"). Solution for using MxFileView in the widget: (1) class = "MxFileView"; (2) check "Inherit Module from Target" (or uncheck it and manually enter "FilesTestAWidget"); (3) in the app target, make sure that both MxFileView.swift and MxFileView.xib include FilesTestAWidget in their Target Membership.
    – Kenster999
    Sep 10, 2018 at 18:20
  • This happened to me on a new project from the default template in Xcode 10.1 (a single iOS app target, and 2 test targets). The checkbox was unchecked for all of my custom view controllers (and so the placeholder text was "None"). After going through and checking the checkbox for every custom view controller in my storyboard, the problem was resolved.
    – Mason
    Jan 24, 2019 at 6:56
59

This worked for me..

Check your compiled source, whether that file(e.g; ViewController.m) is added or not, in my case ViewController file was not added so it was giving me the error..

enter image description here

3
  • @CarmenA You only ever add '.m' files to Compile Sources. This really is the correct (& only) solution for some.
    – Jacksonkr
    Feb 10, 2016 at 16:29
  • I tried several of the other solutions with no luck. This did the trick. For some odd reason one target was missing the one source file that was giving me fits.
    – galactikuh
    Jan 10, 2018 at 13:19
  • for me too.. Happened because of some get conflict resolution
    – Eldhose
    Aug 18, 2018 at 7:01
48

This can happen in any Xcode above 6.0. It happened to me after renaming some ViewController classes in Swift project (but I guess it will happen with Obj-C too). You just have to open the interface builder, go to Identity Inspector of ViewController that had its class renamed, select class and press Enter. That will reassign renamed class to selected ViewController and also reset Module Value which gets lost after renaming the class.

Update for Xcode 8.1 (probably 8.0 too):

Xcode 8.1 just crashes. Simply and annoyingly just crashes and doesn't print anything. I was chasing that phantom crash for an hour just to find out that it was this very same thing - unassigned class in IB. If you're getting some phantom crashes, double check IB for unassigned classes first.

2
  • thanks for this. it appears that following your suggestion causes Xcode to update the module (under the class in IB) from None to Current. i'm thinking the issue is that simply entering the name w/out hitting enter fails to trigger a module update by Xcode. Dec 12, 2016 at 21:40
  • This worked for me. I inadvertently renamed a controller class, so it obviously no longer existed when the view controller was loaded.
    – Litehouse
    May 13, 2017 at 13:39
47

Enabling Inherit Module From Target took the correct target module. That solved the issue.

enter image description here

2
  • Confirm. This helped me solving the issue.
    – Chris8447
    Jul 14, 2019 at 13:53
  • I usually have this issue when I convert a view controller from Objective-C to Swift. I retype the last letter and press Enter. Should do the trick as well.
    – DevNebulae
    Feb 29, 2020 at 18:47
33

Sometimes the controller you are providing loses its target membership from the current application. In that case, pressing enter on the "Module" field will do nothing. Go to the controller and make sure that it has target membership set to the current app.

3
  • This was the problem for me as well - multiple targets lead to the class file accidentally not being included in the target I was building. Jul 6, 2015 at 14:32
  • I merged files and misses this in one of my targets, great answer Sep 14, 2015 at 18:38
  • Good one, merge pbx broke the target membership values.
    – some_id
    Feb 20, 2017 at 15:15
33

My answer: set custom Module equal to the custom Pod name (in my example - custom class name) like on the screenshot attached

This solution is for a specific case: for custom views classes from Pod (or Carthage) framework.

Infrastructure: XCode8, Swift3

enter image description here

0
19

Selecting the proper Module for my Custom Class I solved this problem .

Here it is :

enter image description here

0
18

I fixed it by doing exactly the opposite of what ChikabuZ suggested (thanks for pointing it out, though). In the storyboard file, find this:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass" customModule="AppName" customModuleProvider="target" sceneMemberID="viewController">

and replace it with this:

<viewController storyboardIdentifier="StoryboardId" id="SomeID" customClass="CustomClass" sceneMemberID="viewController">

I can't believe how many hours I'm losing getting around bugs in the Swift compiler and Xcode 6

13

I faced this problem in Xcode 8, to resolve it I had to modify storyboard in the text editor.

In general, look up for your control and remove customModule and customModuleProvider from control entity.

Did a trick for me.

1
  • Hah! Nice hack :)
    – Vexy
    Jan 3, 2018 at 16:47
12

I had the same problem.

In my case, Xcode wasn't adding my custom class to: Target > Build Phase > Compile Sources.

So I recommend you to verify if your CustomClass.m is there.

enter image description here

I hope this helps you.

1
  • This is what happened to me, and fortunately found my way out! I was coming here to answer but you were first. Thanks!!! Oct 23, 2017 at 12:28
11

You need to check the box "Inherit Module From Target" Checkbox

enter image description here

9

I faced this issue in Xcode 6.1 when I removed Main.storyboard , the LaunchScreen.xib file and the default ViewController classes from my project.

I fixed it by deleting the Launch Screen File and Main Interface entries from Info.plist

9

Check if your class has right Target Membership.

8

I googled everywhere for this. None of the answers work for me until i met 1 dude who asked me to move my project folder to desktop. It just worked automatically. Apparently if you have you project folder to deep in many folders, XCODE actually breaks.

2
  • I got this problem in Xcode 7 beta 5 again since I got it in Xcode 6 before. This time, this method works for me.
    – Jake Lin
    Aug 21, 2015 at 14:37
  • 1
    In visual studio there is a similar problem. But over there, we get a clear warning message saying the path is too long and things cannot be added or edited. Not sure if its the same thing with XCODE, but after that episode i keep all my projects either in documents or desktop and never had this problem again. I even gave this advice to someone using Xamarin Studio and it also worked for them...
    – VBaarathi
    Sep 17, 2015 at 23:54
7

These steps work for me.

1) Clear Derived Data.
2) Remove .h and .m files
3) Create .h and .m files Again

2
  • This worked for me as well. I even made it work without clearing derived data.
    – jaytrixz
    Aug 4, 2015 at 14:34
  • This was worked for me, thanks a lot Arwin, But still I am not getting that why it's raising such error because I did not modify anything in the class or in IB before Nov 12, 2015 at 16:58
7

I solved this by opening my storyboard file as source code and using command-F to search for my unknown class and delete the custom class associated with it.

0
6

What @gfrs said is correct, you need to set the Module. However I once ran into an issue that my class wasn't listed in the Class dropdown. Eventually I removed the swift file, re-started Xcode and re-created the file. Finally the class was listed and could be used in Storyboard.

Also have a look at this answer, which looks like to solve the 'real' problem I encountered.

1
  • Removing and re-adding class file worked for me. Thanks! Oct 8, 2015 at 8:48
6

I solved this problem by typing in the Module name (unfortunately the drop list will show nothing...) in the Custom Class of the identity inspector for all the View controller and views.

You may also need to indicate the target provider. To achieve this objective you can open the storyboard in sourcecode mode and add the "customModuleProvider" attribute in both ViewController and View angle brackets.

6

My solution (Xcode 8.1 Swift 3.0):

Unknown class xxx in Interface Builder file.

Open StoryBoard as Source Code and search for xxx. Remove attribute which contains value xxx. Build and Run.

3
  • WTF? This was absolutely necessary for me, thank you. I had to delete the customModule="" customModuleProvider="" Jan 11, 2017 at 0:00
  • 1
    If we try to publish an application to the app store that contains an error like this, the application is refused without thought. Jan 11, 2017 at 0:34
  • I disagree. I just submitted a build that I had to modify this way to TestFlight and it's ready for Beta Testing... we shall see what happens on the actual app store, but it's an IB bug IMO. Thanks! Jan 11, 2017 at 1:04
4

In my case, I added a flag -ObjC to Other Linker Flags in project settings to make it work. Also I tried with -all_load flag and it worked well too.

enter image description here

3

In my case, the class referenced in the Storyboard / xib did not have Target Membership set.

To fix, give that class's .h and .m files the same Target Membership as your other classes.

No target membership set.

2
  • This was my problem, but while trying various solutions I caused the problem that Epic Byte's answer fixes. You must have your source code in the target you are building, but also in IB you need to set the view controller to be part of the current target. Feb 3, 2017 at 22:01
  • Target membership was my problem also, looked everywhere, but thanks to this answer I could solve it.
    – Borzh
    Feb 28, 2017 at 21:08
3

My solution was to remove @objc from Custom class definition.

1
  • 2
    Some example with explanation would be great. Jul 15, 2015 at 11:20
2

I had the same problem with Xcode Version 6.1 (6A1052d). I think the problem appears if you renamed your App / Xcode Project.

My solution was to add the module name in the interface builder manually.

2

I faced the problem when I ported the storyboard from Swift project to Objective-c project, noticing vvkuznetsov's answer, it turned out the two project using same identifier. I "Product -> Clean" and tap Enter key on the Module and Class text field. the issue went away.

2

I fixed this along the lines of what Laura suggested but I didn't need to recreate the files.

Using XCode 4, in the Project Navigator, select the .m file that contains the class that it is complaining about

Go to View->Utilities->Show File Inspector (this will show the File Inspector to the right, with that .m-file info)

Open the Target Membership section and make sure that your target is selected for this .m-file

When I added my .m file to my project, it didn't add it to my default target for some reason and that caused me to get the error you mentioned.

0
2

My issue was user error. I had a generic UIView in my storyboard and in the Custom Class section of the Identity Inspector I had accidentally changed the name from UIView to gibberish.

All it took to fix was to change it back to UIView.

1
  • I did the same thing, but I had accidentally added the Custom View Controllers name to the ViewControllers root view's custom class section. So I was looking to see why View Controller wasn't able to be found when it was the root view the whole time.
    – TMin
    May 13, 2020 at 13:57
1

What only worked for me is actually adding the module name to the xib file...

Sooo, the xib files look like this:

mymodule.MyViewController.xib (Module being the name of the proyect, usually)

HORRIBLE solution in my opinion, but that is supposedly how Apple wants us to do it now.

This question shows 3 possible work arounds back in beta 4 ... apparently Apple has not been very helpful in this situation according to some because they call it "Working as intended."

Not the answer you're looking for? Browse other questions tagged or ask your own question.