Reputation: 2466
Even though Interface Builder is aware of a MyClass
, I get an error when starting the application.
This happens when MyClass
is part of a library, and does not happen if I compile the class directly in the application target.
Upvotes: 261
Views: 174852
Reputation: 2144
This doesn't really have anything to do with Interface Builder, what's happening here is the symbols aren't being loaded from your static library by Xcode. To resolve this problem you need to add the -all_load -ObjC
flags to the Other Linker Flags
key the Project (and possibly the Target) Build Settings.
Since Objective-C only generates one symbol per class we must force the linker to load the members of the class too by using the -ObjC flag, and we must also force inclusion of all our objects from our static library by adding the -all_load
linker flag. If you skip these flags sooner or later you will run into the error of unrecognized selector
or get other exceptions such as the one you've observed here.
Upvotes: 73
Reputation: 1332
In my case, the class couldn't be found because it was a classed defined in an extension inside the framework like so:
extension Buttons {
public class MyButton: UIButton {
// ...
}
}
When I extracted the class from the extension, the Storyboard could finally find the class (MyFrameworkButton):
extension Buttons {
public typealias MyButton = MyFrameworkButton
}
public class MyFrameworkButton: UIButton {
// ...
}
Upvotes: 0
Reputation: 2676
After trying most of the suggestions here wihtout success, I just renamed my class and then renamed it manually in the xib file (with open as source code). Problem then went away.
Upvotes: 0
Reputation: 498
My case - Trying to use a Class from a swift framework in my objective c project, I got this error. Solution was to add Module (swift framework) of the class in Interface builder/ Storyboard as shown below. Nothing else
Upvotes: 15
Reputation: 1
This problem does not seem to get outdated.
I had the same issue with Xcode 8 and solved it similiar like smilebot:
Open your storyboard file as "Source code" within Xcode:
Search for the class being referred to & remove the whole bit that says
customClass="UnrecognizedClassName"
Upvotes: 4
Reputation: 2466
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.
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.
Upvotes: 224
Reputation: 1416
In my case problem was a dead IBOutlet link. Once this was fixed everything was good again.
Upvotes: 0
Reputation: 615
In my case, I have XCode6, the specified class .m file end up in the wrong place in build phase - It should have been under Compile Sources, but end up in the
Upvotes: 6
Reputation: 22939
I did run into this problem today using Swift.
I changed a class Model.h + Model.m
to a Model.swift
.
This object was used in Interface Builder with the class = Model
.
As soon as I replaced the object the class could no longer be loaded.
What I had to do was to change the class reference in IB from:
Class = Model
Module =
to
Class = Model
Module = <TARGETNAME>
You'll find the <TARGETNAME>
in the build settings. It is also the name that shows up in your generated Swift-Header: #import "TARGETNAME-Swift.h"
Upvotes: 26
Reputation: 2562
I keep having this error with WatchKit over and over again and it seems to be when there is a user interface element that isn't tied to an outlet in code. I guess this is required in WatchKit.
class InterfaceController: WKInterfaceController {
@IBOutlet weak var table: WKInterfaceTable!
}
Important note: just connect the outermost element. For instance if you try to also give a connection for something within the table like a label inside a row you will get a compiler error saying the outlet is invalid and cannot be connected to repeating content.
Upvotes: 0
Reputation: 4846
In my case, the custom UIView class is in an embedded framework. I changed the custom UIView header file to "project" to "public" and include it in the master header file.
Upvotes: 0
Reputation: 10195
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">
Upvotes: 16
Reputation: 1045
In my case I had used a storyboard from another project. After looking at the storyboard file xml (e.g. in TextWrangler) I noticed that one of the "customModule" xml attribute values for a controller was wrong (it was still referencing the old project). Manually changing this fixed the problem.
Upvotes: 0
Reputation: 926
I ran into this in Swift.
Moving the .xib file into the project's Base.lproj folder got rid of this error.
Upvotes: 2
Reputation: 261
In my case was a misspelling "Custom Class" name. Make sure that you check your storyboard for the custom classes that you defined.
Upvotes: 0
Reputation: 4823
I FINALLY fixed this, I had forgotten to add the following code to my .m file:
@implementation MyTableViewCell
@end
So it was being caused because I had made a placeholder @interface for my table cell, that had a connection to an element in the .xib file, but there is a bug in Interface Builder where if no @implementation is specified for a class, it can't find it.
I had gone through all of the steps from other forums of viewing the .xib as source and seeing MyTableViewCell even though I had commented it out of my code. I had tried resetting the simulator. I even tried breaking all of my classes up into separate files named the same as the interfaces, but nothing worked until this.
P.S. in my experience, it doesn't matter if the names of the .h/.m files are different from the names of the @interface. I have several files containing more than one @interface and they work fine.
P.P.S. I have a more detailed explanation of why UITableViewCell and UICollectionViewCell cause this error at https://stackoverflow.com/a/22797318/539149 along with how to reveal it at compile-time using registerClass: forCellWithReuseIdentifier:.
Upvotes: 7
Reputation: 137
This “Unknown class in Interface Builder file” error at runtime come if you have more then one StoryBoard and one of the StoryBoard using the which is not really exists.
Upvotes: 0
Reputation: 4059
In my case I get this error message by a very stupid mistake by me: on interface builder I wanted to set the identifier of a UITableViewCell, but I typed the identifier accidentally to the 'Custom class' entry in interface builder.
I made cells 1000 times before....
Upvotes: 0
Reputation: 19642
In my case it was showing an error for a class that didn't even exist! I suspected it was something that got borked in the storyboard file. If you don't recognize the class file in the error try this:
1) open your project in sublime or another good editor. Search for the class being referred to. 2) remove the whole bit that says
customClass="UnrecognizedClassName"
3) save it. 4) return to xcode and clean the project, and try running it now.
worked for me.
Upvotes: 13
Reputation: 314
This drove me nuts for a bit and none of the suggestions above helped me get rid of the error. Luckily I only had one IB object using the class so I just deleted it and added it back with the same class specified. Error went away...
Upvotes: 1
Reputation: 131
The best way to remove the error is: 1) Select the Class File (.m) 2) Under "Target Membership", "check" the Project name entry
Upvotes: 9
Reputation: 1740
Per Apple Documentation
For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags.
In short add -all_load to "other linker" flags in your "Build Settings" and you should be good.
http://developer.apple.com/library/mac/qa/qa1490/_index.html
Upvotes: 0
Reputation: 2674
I had this issue when I had made a new project with the same name and had run them both in the simulator. I renamed one of the projects, deleted the app in the simulator, then ran a clean and re-build.
Upvotes: 0
Reputation: 784
A lot of answers here but none was the solution, I tracked it down to the storyBoard where the controller had an Invalid custom class (class does not exist after I renamed it)
Upvotes: 0
Reputation: 885
This problem happened to me when I added a picker view and then removed it. In case it will help someone, here's how I solved it finally:
Open Document Outline at XCODE (don't know what is Document Outline? I didn't also - google it.. :) ).
Find the Scene that makes the warning message appear, in the document outline window.
On the problematic scene, stand (click) on View, and then in the Utility (google it) window select the Identity inspector tab and change back the custom class name to default UIView.
That't it. :)
Upvotes: 0
Reputation: 2189
I added the file Under Build Phase in Targets and the issue got resolved. For the steps to add the file, see my answer at:
Apple Mach-O Linker error (APActivityIcon)
Upvotes: 1
Reputation: 1428
In my case I had deleted a class called "viewController" not realising it was selected with the storyboard's identity inspector (under 'Custom Class' up the top).
You just have to simply select the correct class for the view controller in your identity inspector's Custom Class field or add a new class to your project and select that one as your Custom Class.
Worked for me!
Upvotes: 1
Reputation: 711
I had "Unknown class RateView in Interface Builder" where RateView was a subclass of UIView. I had dropped a UIView onto my Storyboard scene and changed the Custom class field to RateView. Still, this error appeared.
To debug, I changed the name of my class to RateView2 and changed all references to match except the Custom class field of the UIView. The error message still appeared as before with RateView as the missing class. This confirmed that the error message was related to the value of the Custom class field. I changed this value to RateView2 and the error message changed to "Unknown class RateView2 in Interface Builder". Progress of sorts.
Finally, I inspected the source code files themselves in the File Inspector. There I discovered that the source code file (which I had copied from a tutorial) was not associated with my Target. In other words, it had no Target Membership. I checked the box that made the class's source code file a member of the target app and the error message went away.
Upvotes: 1
Reputation: 1
I saw this error when I changed a class name, despite updating all relevant .h and .m. Turned out, I had missed updating 'customClass' value in the .storyboard files. That resolved the problem.
Upvotes: 0
Reputation: 4409
From interface builder/storyboard is referred to a class that is not available.
If the is a known class it is not linked.
If the is not a class or just some characters it is probably a typo. In that case check all the fields in the view controller for this 'unknown class'. In the 'Identity Inspector' (3rd from left in the block 'Custom Class' is one field 'Class' which probably contains the wrong value. Normally it lists the field type (UIView / UILabel etc).
Upvotes: 0