How To Fix Error Use Of Unresolved Identifier ‘RootViewController’ In Xcode Swift Project

When I develop an iOS project in Xcode, I create a custom class RootViewController in RootViewController.swift file, this class is a subclass of UIViewController. But during the development process, when I use this custom class to create an object in another swift file ( for example SceneDelegate.swift ), I meet an error which said Use Of Unresolved Identifier ‘RootViewController’ In the Xcode Swift Project. This error message confused me a lot of times, and finally, I fix it, below are the steps and the method to fix it.

1. Fix Use Of Unresolved Identifier ‘RootViewController’ In Xcode Swift Project Error Steps.

  1. First, I create another new cocoa touch class in the project, the class name is TestViewController, it is saved in TestViewController.swift file. This is a whole new class, so I want to test whether the error exists when using this class.
  2. Then I write the below code in SceneDelegate.swift file to create an instance of the TestViewController class, and I found the error does not exist at all. So I think, this error is not because of the old RootViewController class, maybe because of the Xcode build cache.
    var testVC : TestViewController = TestViewController()
  3. Then I click Xcode Product —> Clean Build Folder menu item at Xcode top menu bar to clean the build folder. And then click Product —> Build menu item to build the project again. And now the above error disappear with the source code var rootVC : RootViewController = RootViewController() . So the error is because of the Xcode project build cache, what you need to do is just clean the build folder and build it again.

Subscribe to receive more programming tricks.

We don’t spam!

Subscribe to receive more programming tricks.

We don’t spam!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.