I want to make my project more organized, so I created new groups and dragged files into those groups. I am doing all of this in Xcode, not finder or terminal. However, now, Xcode shows "Cannot find ‘FileName’ in Scope" errors next to references to classes in those files.
How do I solve this problem?
I tried building the project and cleaning the build folder.
3
Answers
I ran into the same issue today with Xcode 12.2 and an iOS 14.2 project. I created a file for a new struct, wrote some code in ViewController that created instances of the struct, and then for housecleaning I moved the struct’s .swift file. At that point I saw the error "Cannot find [type] in scope."
Product | Clean Build Folder didn’t do the trick.
Closing and reopening Xcode worked for me.
I’m not sure if the initial clean helped or not.
There are more detailed answers here, and your particular case may be covered:
SwiftUI 2.0 CoreData issues with new project – 'Cannot find type 'Item' in scope'
I fixed a similar issue today using Xcode 12.3 (12C33):
Solution
Removed the impacted files from Xcode (without trashing them)
Tried adding the files back with the create folder references option selected
Found that this action generated Cannot find ‘type’ in scope error
Resolved the error by removing the files references and select the create groups option when copying the files back into the project.
BTW – I found these methods work while using either the Add Files option or dragging the files/folders into the project.
I found some "hack" to fix it.
Lets say you wanna move folder
Models
to your project. Open AppCode and createModel
group using IDE tools. Then open XCode, selectModel
folder and performAdd files to "Model"
action. It worked out in my case.From my understanding, the problem is with forlders, not with files.