cannot find type in scope xcode 13

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

  • Could you post the code where you get the error message, as well as the needed context ?

  • I've got the same issue. In Xcode 13 only, I get "Cannot find X in scope" errors for all the objective-c stuff that i'm using in Swift, but the project still builds and runs successfully.

  • I've got the same issue. Is there any way to solve this issue?

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?

  • Generally, when you show some code, you should show all the code as text. Adding an image would be helpful as an additional info, but it cannot be a primary info because readers cannot pick up the parts included in the image. Usually, in this sort of errors, you should better show all the headers of ObjectiveC classes and the bridging header. But reading the strange thing, there may be a possibility that your Xcode is malfunctioning and just recalling the old errors when you had not set the bridging header correctly. Have you tried restarting Xcode, or restarting your Mac?

  • I get the same question, and I have tried restarting Xcode or restarting your Mac, but it's an error.

Add a Comment

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.

  • you save my day! thanks a lot

Add a Comment

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

Add a Comment

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!

  • have you found the solution?

Add a Comment

In my case, everything works but Xcode reports errors anyway. In this case, moving around the order of imports in the bridging header helped.

So it's not a real problem but you can solve it anyway.

  • Thank you! Moving stuff around in the bridging header helped me as well.

  • This worked for me

Add a Comment