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 sub class 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 Xcode Swift Project. This error message confused me a lot of time, and finally i fix it, below is the steps and the method to fix it.

invoke custom swift class root view controller in another swift file

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 exist when use this class.
  2. Then i write below code in SceneDelegate.swift file to create an instance of the TestViewController class, and i found the error do 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.
READ :   How To Change UITextField Keyboard Type And Hide Keyboard Automatically When Press Return Key

Leave a Reply

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.