본문 바로가기
모바일개발(Mobile Dev)/IOS개발(ObjectC)

Xcode 6 Strange Bug: Unknown class in Interface Builder file

by 테크한스 2015. 12. 11.
반응형

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've spent hours trying to figure this out, but nothing works! 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.

shareimprove this question
9 
Really? That question was asked 3 years ago. This bug is related to XCODE 6. Not to mention the error message itself is unrelated to the root cause of the issue. – Epic Byte Jul 24 '14 at 16:08
1 
This has just happend to me after first (accidentally) opening a storyboard in Xcode 5 then reopening it in Xcode 6 beta 6. Be very careful switching between Xcode 5/6 at the same project! – Imre Kelényi Aug 22 '14 at 10:41
1 
@ImreKelényi You are right. This happened to me again recently after doing what you just described. – Epic Byte Aug 22 '14 at 18:59
up vote434down voteaccepted

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. Click inside the Module text box, and press enter.

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

shareimprove this answer
19 
For me, clicking inside "Module" and pressing enter did not work consistently, but selecting the "Class" field (and pressing enter) always did the job. – Imre Kelényi Aug 22 '14 at 14:54
1 
@itedi good point, when I get a chance I think I'll add a "Causes" section and list everything that users report caused the issue so we can get a list of what's leading to the issue. – Epic Byte Aug 26 '14 at 18:59
15 
AHHHHHHHHH YOU SAVED MY LIFE – nevermind Oct 11 '14 at 19:08
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 '14 at 20:14
3 
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. – nathan.f77 Nov 7 '14 at 21:57

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">
shareimprove this answer
8 
After reading tons of solutions this is the first one that works for me! The worst is that this bug is still happening on February 2015, when it started to be reported on August 2014. Thanks anyway for fixing a problem that was driving me nuts! – Guillermo Barreiro Feb 10 at 18:48
4 
It feels like going to Android world. Annoying – Ramis Feb 27 at 9:12
1 
Actually in my case i had to remove customModuleProvider, then the error went away. – Maciej SwicMar 11 at 13:15
3 
Guillermo, still happening in Xcode as of end of March! – edsappfactory.com Mar 27 at 15:30
4 
Still happening... it's things like this that make me want to cry :( – Luke May 4 at 22:47

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

@objc(ForumTopicListViewController) class ForumTopicListViewController
shareimprove this answer
3 
This fixed it for me, I had @objc class X and changing to @objc(X) class X worked. – Joe Oct 29 '14 at 13:25
2 
Worked. Curse you XCode... – Lee Whitney Dec 4 '14 at 13:49
1 
You can also try to delete your derived data see stackoverflow.com/questions/24039932/… – user1760527Dec 6 '14 at 15:58 

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.

shareimprove this answer
1 
This was the problem in my case -- I was working on a project with multiple targets and the ViewController in question was not a part of the active target build. Thanks! – dave May 27 at 19:19

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

shareimprove this answer

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

shareimprove this answer

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.

shareimprove this answer

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.

shareimprove this answer

These steps work for me.

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

shareimprove this answer

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

shareimprove this answer

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.

shareimprove this answer

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."

shareimprove this answer

I faced the problem when I ported the storyboard from Swift project to Objective-c project, noticingvvkuznetsov'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.

shareimprove this answer

The solution was different for me. You need to add the .m of the class to the build phase compiled sources of the target.

Hope this helps!

shareimprove this answer

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.

shareimprove this answer

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.

shareimprove this answer

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.

shareimprove this answer

I had this problem after I added a new target, then created a new class using the 'New File' dialog but accidentally failed to check the new target as well as the original target in the creation dialog, so the object was only added to my original target. The solution was to delete the source files (remove reference only) then add them back using 'Add Files', this time checking both targets.

shareimprove this answer

I faced such a problem on Xcode 6 when I deleted the already included ViewController.h & ViewController.m files from my new view based project, and deleted the scene that was related to this class from storyboard, Xcode cashes these files in derived data folder, so if you try to go to Window -> Projects -> your_project and delete the derived data everything will go fine.

shareimprove this answer

Don't use spaces in the project name, otherwise the Custom Class will not find your own classes.

shareimprove this answer

I faced a problem when I created a project with the same name that already existed in my projects directory (though it was deleted some time ago). I wrote my solution therehttp://stackoverflow.com/a/27763697/1654692

shareimprove this answer

It happened to me because my class was marked with @objc and in sotryboard it couldn't find the module. Removing @objc fixed the problem

shareimprove this answer

I had the same problem, but not the same fix.

The project folder was kinda corrupted so i had to copy my project folder to another folder, for example your desktop and after that open the project.

When it opened go to your interface builder project and you will see he recognise your script, Then you click indeed on the name of your script and press enter, u will see the module input will fill it self.

And it will work like a charm! :D

shareimprove this answer

This worked for me when nothing else did. From the project directory in terminal:

[~/Developer/MyProject] grep -rn ViewController * | grep -i xib 

Open the matched files as source code in Xcode and change any instances of ViewController to what you actually need. In my case the file I needed to open as source was Main.storyboard and I changed instances of ViewController to DetailViewController.

I deleted two files from Xcode and main.storyboard which is what I believe caused this issue for me to begin with.

shareimprove this answer

In mij case the ViewController.h/m where in a lib. The projects still builds but since Xcode 6.3 the above error was shown at run-time. Moving both files back into the project solved the issue.

shareimprove this answer

I was playing with Spring class. And this error happend to me because i used folder as reference when moving whole folder class to project instead of creating groups. So this was my solution, dont use folder as reference but create groups.

shareimprove this answer

in my case , i setup app as universal app, so xcode creates two storyboards.but i was only using(designed) only iPhone storyboard. and trying to run app in iPad.for resolve problem just need to make app as only for iPhone and works great.

shareimprove this answer

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

shareimprove this answer
1 
Some example with explanation would be great. – Nilambar Jul 15 at 11:20

I had the same problem with Xcode 6.3 when I add files to "myapp". That's because I choose "create folder reference" instead of "create groups".I delete these files and add them again with the "create groups" option.And the problem fixed.

shareimprove this answer

Select your unknown class file, open file inspector tab, check your target name in Target Membership. There you go.

shareimprove this answer


반응형

'모바일개발(Mobile Dev) > IOS개발(ObjectC)' 카테고리의 다른 글

A better way to access NSUserDefaults  (0) 2015.12.11
Sending Image from Xcode to Server  (0) 2015.12.11
ABOUT PLIST  (0) 2015.12.10
english locale for the displayName  (0) 2015.12.10
Facebook Login in iOS App  (0) 2015.12.06