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.
1. Fix Use Of Unresolved Identifier ‘RootViewController’ In Xcode Swift Project Error Steps.
- 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.
- 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()
- 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.