即使接口生成器是一个MyClass,我得到一个错误时启动应用程序。

当MyClass是库的一部分时,就会发生这种情况,如果直接在应用程序目标中编译该类则不会发生这种情况。


当前回答

In my case I got this error because I'd tried to save some work by creating a new project and then deleting several of the source files and copying over the source files of the same name from the working project. I also copied my MainStoryBoard file which was looking for my RootViewController. However, when I had deleted the original RootViewController and then added in the RootViewController from the previous product, evidently the Add Files operation failed to "check" the target box as suggested above. By merely visting all of the newley imported ".m" files and making sure that the target membership box was checked, all was well. I think what was happening was that the storyboard file was looking for a class that had been "excluded" from the link because the target membership was unchecked. Making sure the required files for the target are so designated in the target membership in the file inspector did the trick. Thanks Pat! (see above)

其他回答

I tried most of the solutions you guys suggested above but to no avail. After reading the solution from user776904's I suspected I was having the same issue as I had rebuilt my app from the ground up but copied the xib files from the previous project. I suspected the xib file had a reference to the old project that was causing my error so I simply deleted my mainwindow_ipad.xib file and copied in a new one from a clean new project. This solved it. And I was not game enough to start changing bits of the xib file in its source code.

尽管在运行时打印了“未知类MyClass in Interface Builder file.”错误,但这个问题与Interface Builder无关,而是与链接器有关,因为没有代码直接使用它,所以链接器没有链接类。

当.nib数据(从.xib编译)在运行时加载时,MyClass使用字符串引用,但链接器不分析代码功能,只分析代码存在,所以它不知道。由于没有其他源文件引用该类,链接器在生成可执行文件时将其优化为不存在。因此,当Apple的代码试图加载这样一个类时,它无法找到与之相关的代码,并打印警告。

默认情况下,Objective-C目标将默认设置-all_load -ObjC标志,这将保留所有的符号。但我一开始的目标是c++,没有这个。尽管如此,我还是找到了一种方法,使链接器保持侵略性。

我最初使用的黑客是添加一个空的静态例程,如:

+(void)_keepAtLinkTime;

它什么都不做,但我会调用一次,比如:

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

这将迫使链接器保留整个类,错误就会消失。

正如jlstrecker在评论中指出的那样,我们实际上并不需要添加_keepAtLinkTime方法。简单地调用一个现有的函数,例如:

   [MyClass class];

(只要你是从NSObject派生的)。

当然,您可以在代码的任何位置调用它。我猜它甚至可能是不可访问的代码。这个想法是欺骗链接器,让它认为MyClass在某个地方被使用了,这样它就不会那么积极地优化它。

Xcode 6.3.2和Swift 1.2

快速定义视图。确保重写init(coder aDecoder: NSCoder)。视图控制器的Objective-C定义。还有,梨树上的笔尖。

将模块名称添加到Nib详细信息检查器,在其中选择类。

在尝试了这里的大多数建议都没有成功之后,我只是重命名了我的类,然后在xib文件中手动重命名它(源代码是开放的)。问题就这样解决了。

我只是想添加这个答案,因为这里的大多数答案(如果不是所有答案)都假设该类实际存在。只是链接器/编译器太笨了,看不到它。因此,答案围绕要么提醒链接器类的存在或创建一个黑客'强迫'存在它。

我的问题发生时,这条消息实际上是谈论一个不存在的类..因此,一个例子将是我回到一个旧的git修订版,没有特定的类的知识。然而编译器会报错该类不存在。

解决方案吗?

用核武器摧毁整个世界!首先删除所有构建文件,删除该目录下的所有内容 ~ /图书馆/开发/ Xcode / DerivedData 从手机中删除应用程序(如果使用模拟器,则清除模拟器内容)

之后你就可以去了

我在《Swift》中遇到过这种情况。

将.xib文件移动到项目的Base中。Lproj文件夹摆脱了这个错误。