8

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.

4 Answers 4

9

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'

Sign up to request clarification or add additional context in comments.

4 Comments

How does this bug make it to production, and persist even in .3 build?...
Would that I knew. Visual Studio has its issues, too, but I don't have enough experience in XCode to know what to expect.
Same Xcode issues, another decade. Sigh... Honestly Apple software has mostly been coasting downhill since the former CEO passed away...still no CEO at Apple yet.
That is an example of why tech companies need engineers (at least hobbyist engineers) as CEO. Former CEO was at least a hobbyist engineer and obviously his co-founder was an engineer. Sad that I spent so much of the past calendar decade using Xcode.
0

I fixed a similar issue today using Xcode 12.3 (12C33):


Solution

  1. Removed the impacted files from Xcode (without trashing them)

  2. Tried adding the files back with the create folder references option selected

  3. Found that this action generated Cannot find 'type' in scope error

  4. 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.

Comments

0

I found some "hack" to fix it.

Lets say you wanna move folder Models to your project. Open AppCode and create Model group using IDE tools. Then open XCode, select Model folder and perform Add files to "Model" action. It worked out in my case.

From my understanding, the problem is with forlders, not with files.

Comments

0

If none of the other answers work for you (Clean build folder and restart Xcode) then delete the derived data in DerivedData/{Project Name}_some_hash

You can find that folder quickly by going to Settings in Xcode. There is a link to it if you go to Derived Data under the Xcode menu at top → Settings → Locations.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.