Unknown Class in Interface Builder

Xcode 6 Bug: Unknown class in Interface Builder file

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:
Sample Image

Unknown class in Interface Builder file - Xcode 8 Swift 3

What ended up solving my problem was creating a new project and seeing how the original Main.storyboard references its .swift file in the XML, which looks like this

                <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Sandbox" customModuleProvider="target" sceneMemberID="viewController">

where the important aspect is customClass="ViewController"

By taking this, and editing my project's TutorialView.storyboard by hand and adding in customClass="TutorialViewController I resolved the error.

Unknown class MyClass in Interface Builder file error at runtime

Despite the "Unknown class MyClass in Interface Builder file." error printed at runtime, this issue has nothing to do with Interface Builder, but rather with the linker, which is not linking a class because no code uses it directly.

When the .nib data (compiled from the .xib) is loaded at runtime, MyClass is referenced using a string, but the linker doesn't analyze code functionality, just code existence, so it doesn't know that. Since no other source files references that class, the linker optimizes it out of existence when making the executable. So when Apple's code tries to load such a class, it can't find the code associated with it, and prints the warning.

By default, Objective-C targets will have -all_load -ObjC flags set by default, which will keep all of the symbols. But I had started with a C++ target, and didn't have that. Nevertheless, I found a way around this, which keeps the linker aggressive.

The hack I was originally using was to add an empty static routine like:

+(void)_keepAtLinkTime;

which does nothing, but that I would call once, such as:

int main( int argc, char** argv )
{
[MyClass _keepAtLinkTime];
// Your code.
}

This would force the linker to keep the whole class, and the error disappears.

As jlstrecker pointed out in the comments, we do not really need to add a _keepAtLinkTime method. Simply calling an existing one, such as:

   [MyClass class];

does the trick (as long as you derive from an NSObject).

Of course, you can call this in any location of your code. I guess it could even be in unreachable code. The idea is to fool the linker into thinking that MyClass is used somewhere so that it isn't so aggressive in optimizing it out.

Xcode 6.3.2 & Swift 1.2

Swift definition of view. Be sure to override init(coder aDecoder: NSCoder). Objective-C definition of view controller. And, a nib in a pear tree.

Add Module Name to Nib details inspector where you pick your class.

Unknown Class **** in Interface Builder file

Sometimes IBuilder 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">

Unknown class info in Interface Builder file

Try this, in order:

  1. Product->Clean in Xcode
  2. Delete the app from the simulator or device
  3. Restart Xcode
  4. (Build &) Run again

If this doesn't help, you likely have a reference to a class in the nib or storyboard that you have to manually find and remove.

Xcode 7.1 Swift 2 Unknown class in Interface Builder file

In storyboard below the Custom Class field the module is set to None. Change that to your app module or just remove and enter class again, it should set to default like this:

Sample Image

Unknown class in Interface Builder file

It turns out the bits on the iPhone simulator were out of sync with XCode. I did a 'Reset Content and Settings' and everything works :) Who knew?



Related Topics



Leave a reply



Submit