skip to Main Content

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


  1. 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'

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search