PerfectFiasco
PerfectFiasco

Reputation: 157

How to move files in Xcode without causing "Cannot find 'FileName' in Scope"?

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.

Upvotes: 7

Views: 5261

Answers (4)

Ben
Ben

Reputation: 3804

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.

Upvotes: 0

Ildar Zaripov
Ildar Zaripov

Reputation: 551

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.

Upvotes: 0

Tommie C.
Tommie C.

Reputation: 13181

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.

Upvotes: 0

Rethunk
Rethunk

Reputation: 4093

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'

Upvotes: 8

Related Questions