[英]Unknown class in Interface Builder file - Xcode 8 Swift 3
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. 重命名后,我试图修复从链接
TutorialView.storyboard
到TutorialViewController.swift
通过更新故事板的Custom Class
到TutorialViewController
,这是完成链接的正确方法。 This in fact caused the above error. 这实际上导致了上述错误。
Disclaimer: I'm aware this is similar to this SO post but I wanted to make this question and answer my solution, as that post does not have an accepted answer. 免责声明:我知道这与SO帖子类似,但我想提出这个问题并回答我的解决方案,因为该帖子没有接受答案。 I'm hoping I can save someone all the time it took me to figure this out.
我希望我能一直拯救别人,这让我想出来。
Check if the Inherit from Target
is selected in the interface builder to your custom view. 检查是否在界面构建器中选择了
Inherit from Target
到自定义视图。 That actually did the trick for me. 这实际上对我有用。
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. 如果您有多个目标,请检查是否为所有目标选择了自定义类,或者至少是您正在运行的目标。
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
我解决了错误。
You could also try selecting the CustomClass -- Class again to your class name and hit return. 您也可以尝试再次选择CustomClass - Class到您的类名并点击返回。 It would help update the class name associated with the viewController.
它将有助于更新与viewController关联的类名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.