skip to Main Content

I am facing a strange error when writing the simplest of swift programs in Xcode 12.0.1.
enter image description here

It says that it can’t find T1 in scope when it is very much in scope. I feel that it must be trivial to solve this problem, and I tried ⌘ + ⇧ + K and closed Xcode and reopened, but the problem persists. Anyone knows how this can be solved?

2

Answers


  1. Sometimes there are ghost errors that seem to not go away, even when Xcode is closed and reopened, but are fixed by either changing the code then changing it back, or clicking build anyway and the build succeeds.

    Otherwise, the color highlighting of T1 in the return doesn’t match in the variable declaration. That suggests name clashing. Are there any types or global variables called T1, even if there’s nothing else in your code maybe it’s a built-in type or similar? Try naming the variable differently.

    Login or Signup to reply.
  2. I got the same error and was searching around, but couldn’t find an answer to it so I’ll share it here for others to find as well. For my part, I was creating a view in a package and was referencing that view from an app.

    I got the Cannot find [Type] in scope and turns out I forgot to put the public attribute on the view struct.

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