Interface Builder 文件中的未知类 - Xcode 8 Swift 3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41859698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unknown class in Interface Builder file - Xcode 8 Swift 3
提问by Greg Hilston
I ran into the following error
我遇到了以下错误
Unknown class TutorialViewController.swift in Interface Builder file.
Interface Builder 文件中的未知类 TutorialViewController.swift。
when renaming the default files Main.storyboard
and ViewController.swift
to my desired naming convention of TutorialView.storyboard
and TutorialViewController.swift
respectively.
重命名默认的文件时Main.storyboard
,并ViewController.swift
到我想要的命名规则TutorialView.storyboard
和TutorialViewController.swift
分别。
I renamed the files by physically renaming the file names in Xcode and updating the class name of TutorialViewController.swift
.
我通过物理重命名 Xcode 中的文件名并更新TutorialViewController.swift
.
After renaming, I tried to fix the link from TutorialView.storyboard
to TutorialViewController.swift
by updating the storyboard's Custom Class
to TutorialViewController
, which is the correct way to complete the link. This in fact caused the above error.
重命名后,我尝试通过更新情节提要的to来修复从TutorialView.storyboard
to的链接,这是完成链接的正确方法。这实际上导致了上述错误。TutorialViewController.swift
Custom Class
TutorialViewController
Disclaimer: I'm aware this is similar to this SO postbut I wanted to make this question and answer my solution, as that post does not have an accepted answer. I'm hoping I can save someone all the time it took me to figure this out.
免责声明:我知道这类似于这个 SO 帖子,但我想提出这个问题并回答我的解决方案,因为该帖子没有被接受的答案。我希望我能拯救一个人,我花了我所有的时间来解决这个问题。
采纳答案by Greg Hilston
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
最终解决我的问题是创建一个新项目并查看原始项目如何Main.storyboard
在 XML 中引用其 .swift 文件,如下所示
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Sandbox" customModuleProvider="target" sceneMemberID="viewController">
where the important aspect is customClass="ViewController"
重要的方面是 customClass="ViewController"
By taking this, and editing my project's TutorialView.storyboard
by hand and adding in customClass="TutorialViewController
I resolved the error.
通过采取这一点,并TutorialView.storyboard
手动编辑我的项目并添加,customClass="TutorialViewController
我解决了错误。
回答by Shruti
Check if the Inherit from Target
is selected in the interface builder to your custom view. That actually did the trick for me.
检查是否Inherit from Target
在界面构建器中选择了自定义视图。这实际上对我有用。
If your view happens to be within a .bundle
file that gets copied to a different target, then you'll need to explicitly set the module target.
如果您的视图恰好位于.bundle
复制到不同目标的文件中,那么您需要显式设置模块目标。
If you have multiple targets, then check if the custom class is selected for all the targets or at least the one which you are running.
如果您有多个目标,请检查是否为所有目标或至少为您正在运行的目标选择了自定义类。
回答by Qiaochu Guo
You could also try selecting the CustomClass -- Class again to your class name and hit return. It would help update the class name associated with the viewController.
您也可以尝试再次选择 CustomClass -- Class 到您的班级名称并点击返回。这将有助于更新与 viewController 关联的类名。