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

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?
asked Dec 11, 2020 at 3:03
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.
answered Dec 11, 2020 at 3:09
8
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.
answered Aug 23, 2022 at 7:06
![]()
Kent RobinKent Robin
1,83618 silver badges18 bronze badges
I had many swift compiler errors of this type : «Cannot find type ‘className’ in scope» after passing from Xcode 12.5 to Xcode 13. And the error is always referred to Objective-C classes.
The project is for an iOS 11 app for iPad.
The bridging-header is correctly set and the project with the same build-settings has never given this error before Xcode 13.
I’ll try to clean the derived data folder without success.
the strange thing is project compile successfully and I can run on simulator as well but after few second from a successful compilation on any swift files that use objective-c class is fired
the swift compiler error.
Any idea? thanks
Accepted Reply
I finally solved the problem removing all #import in bridging header of files contained in my pods libraries
Replies
I add sample code and screen of the error, i hope is useful, PersonalEditorContentPageVC and QWidget are Objective-c classes.
class ContactViewController:PersonalEditorContentPageVC {
var activeWidget:QWidget?
var prevActiveWidget:QWidget?
Go to build settings and build after setting Precompile Bridging Header YES -> NO.
You can show no errors.
But codes defined by objec aren’t recognized. It is not able to jump to definition.
I finally solved the problem removing all #import in bridging header of files contained in my pods libraries
I finally solved the problem with Product -> Clean Build Folder
I am seeing complier error on WKMediaCaptureType and WKPermissionDecision. I made sure WebKit is imported in WebViewDelegationHandler.swift file. Cannot find type ‘WKMediaCaptureType’ in scope. Cannot find type ‘WKPermissionDecision’ in scope. Any clue why it is happening. Thanks in advance!
When those simple annoyances are too frustrating! Yes we have all been there and I was really hoping that Apple would have fixed what is obviously a bug.
Historically I have found Core Data annoying to work with… so for a while now I have been managing the database using Realm. However, with Realm now significantly bloating (553MB) and the Realm Browser app on OSX no longer usable, it was time to visit my old friend. With open arms it tripped me up straight away. I had deleted the cursory Item entity and added a new entity named Person. With that change I was greeted with Cannot find ‘Person’ in scope. As I had deleted Item, even if I added that back in to the code — correctly the error was Cannot find ‘Item’ in scope. At least I had something working. Or was it really working for me…
I needed to give Xcode a good clean.
The clearing process I did to get it running again was:
Clean build folder (shift + command + k) Close Xcode completely Delete 'DerivedData' content (/Library/Developer/Xcode/DerivedData) Open Xcode and your project again Try to build and run it again
Deleting derived data
Run the following command to delete the contents of your DerivedData directory, replacing {your-name}:
rm -rf /Users/{your-name}/Library/Developer/Xcode/DerivedData/*
Related articles
Andrew Fletcher
•
18 Jun 2022
Andrew Fletcher
•
04 May 2022
Andrew Fletcher
•
27 Apr 2022
ionic app in Xcode white screen cannot find files issue
While loading an ionic project, in Xcode when performing a run routine I had the following response
⚡️ Loading app at capacitor://localhost…
2022-04-17 15:54:01.318573+1000 App[74515:7355495] [Process] 0x7f8758828820 — [pageProxyID=5, webPageID=6, PID=74520]…
Comments
groue
changed the title
Xcode 12 beta error: «Cannot find ‘CodingKeys’ in scope»
Xcode 12 error: «Cannot find ‘CodingKeys’ in scope»
Sep 20, 2020
tobyspark
added a commit
to tobyspark/ORBIT-Camera
that referenced
this issue
Sep 26, 2020
Also: currently requires Xcode 12.2 beta (see groue/GRDB.swift#804) Also: GRDB swift package is confused/confusing. Could not update to GRDB 4.12 to get updated migration query functions (submodule errors). Ended up having to go to 5.0, but the ValueObserver changes documented aren't part of the build that's pulled in, despite delaring as 5.0
tobyspark
added a commit
to tobyspark/ORBIT-Camera
that referenced
this issue
Sep 26, 2020
Also: currently requires Xcode 12.2 beta (see groue/GRDB.swift#804) Also: GRDB swift package is confused/confusing. Could not update to GRDB 4.12 to get updated migration query functions (submodule errors). Ended up having to go to 5.0, but the ValueObserver changes documented aren't part of the build that's pulled in, despite delaring as 5.0
tobyspark
added a commit
to tobyspark/ORBIT-Camera
that referenced
this issue
Oct 6, 2020
Also: currently requires Xcode 12.2 beta (see groue/GRDB.swift#804) Also: GRDB swift package is confused/confusing. Could not update to GRDB 4.12 to get updated migration query functions (submodule errors). Ended up having to go to 5.0, but the ValueObserver changes documented aren't part of the build that's pulled in, despite delaring as 5.0
tobyspark
added a commit
to tobyspark/ORBIT-Camera
that referenced
this issue
Mar 31, 2021
Also: currently requires Xcode 12.2 beta (see groue/GRDB.swift#804) Also: GRDB swift package is confused/confusing. Could not update to GRDB 4.12 to get updated migration query functions (submodule errors). Ended up having to go to 5.0, but the ValueObserver changes documented aren't part of the build that's pulled in, despite delaring as 5.0
tobyspark
added a commit
to tobyspark/ORBIT-Camera
that referenced
this issue
Mar 31, 2021
Also: currently requires Xcode 12.2 beta (see groue/GRDB.swift#804) Also: GRDB swift package is confused/confusing. Could not update to GRDB 4.12 to get updated migration query functions (submodule errors). Ended up having to go to 5.0, but the ValueObserver changes documented aren't part of the build that's pulled in, despite delaring as 5.0
So, I’m creating a SwiftUI app, and have set up Core Data models. These models have been working properly up until yesterday.
Chasing around a bug, I decided to re-generate the Core Data models (Editor > «Create NSManagedObject Subclass…»). I have done this many times in the past while setting up Core Data, and haven’t had any issues. This time, after deleting the old files and generating the new files in the same location, XCode can no longer find the Core Data models. I now have 135 build errors, all to do with «Cannot find type ‘whatever’ in scope».
The files are in the correct place in the Project Navigator, and in the right place when I look in Finder. I have cleaned workspace (cmd + shift + k), restarted XCode, restarted the computer, and every combination of these 3 you can think of. When XCode re-indexes, nothing new is found. If I do a reference search in XCode, the new files are not included in the search results, so XCode really has no idea that these files are there.
I found one suggestion online of adding a new attribute to a model, build, then remove the attribute. This also did not help.
How can I fix this? Am I able to manually point the broken references to the new correct file? Is there a way I can tell XCode that these files do actually exist?