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

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


当前回答

在我的例子中,它显示了一个甚至不存在的类的错误!我怀疑这是故事板文件中被删除的东西。如果你不能识别错误中的类文件,试试这个:

1)用sublime或其他好的编辑器打开你的项目。搜索被引用的类。 2)把上面写的全部去掉

customClass="UnrecognizedClassName"

3)节约。 4)返回xcode并清理项目,现在试着运行它。

为我工作。

其他回答

只需删除MyClass。M和。h,并将它们再次添加到项目是我的工作。

尽管在运行时打印了“未知类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详细信息检查器,在其中选择类。

每个苹果文档

对于64位和iPhone操作系统应用程序,有一个链接器错误 阻止-ObjC从静态库中加载对象文件 只包含类别,不包含类。解决方法是使用 -all_load或-force_load标志。

简而言之,在你的“构建设置”中添加-all_load到“其他链接器”标志,你应该没问题。

http://developer.apple.com/library/mac/qa/qa1490/_index.html

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)

这里有很多答案,但没有一个是解决方案, 我追踪到storyBoard,控制器有一个无效的自定义类(类不存在后,我重命名它)