4

I ran into the following error

Unknown class TutorialViewController.swift in Interface Builder file.

when renaming the default files Main.storyboard and ViewController.swift to my desired naming convention of TutorialView.storyboard and TutorialViewController.swift respectively.

I renamed the files by physically renaming the file names in Xcode and updating the class name of 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.

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. I'm hoping I can save someone all the time it took me to figure this out.

Community
  • 1
  • 1
Greg Hilston
  • 2,397
  • 2
  • 24
  • 35

3 Answers3

11

Check if the Inherit from Target is selected in the interface builder to your custom view. 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.

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.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Shruti
  • 131
  • 1
  • 4
4

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.

  • Yea, this will work to "refresh" the reference but if the reference was incorrect in the first place, it'll have no affect. Thanks for the answer! – Greg Hilston Sep 16 '17 at 18:53
2

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

                <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="Sandbox" customModuleProvider="target" sceneMemberID="viewController">

where the important aspect is customClass="ViewController"

By taking this, and editing my project's TutorialView.storyboard by hand and adding in customClass="TutorialViewController I resolved the error.

Greg Hilston
  • 2,397
  • 2
  • 24
  • 35