Skip to content

Instantly share code, notes, and snippets.

@phynet
Last active August 13, 2020 20:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phynet/f00b5ca18aef96c39f2d84cc077965f1 to your computer and use it in GitHub Desktop.
Save phynet/f00b5ca18aef96c39f2d84cc077965f1 to your computer and use it in GitHub Desktop.
implicit import bridging header in module is deprecated

now in swift 4 you just have to import a briding header into Test target and reference objc-class .h files there...using @testable import nameOfYourApp should work

In Swift there's a message in "Test Target" that states that the bridging header will be removed in newer versions of swift. I'm using mixed objc and swift clasess, but the UnitTest class is a swift file. Using @testable key was there in code

  @testable import YourProject

You fix it by adding in your Test area the bridging header with objc headers that your test will use:

  #import "Project-Bridging-Header.h"

Oldated ..

and deleting the @testable inside your test

 import YourProject 
@sonjh1217
Copy link

Thank you

@hlung
Copy link

hlung commented Jul 17, 2017

Thanks! Though I cannot remove @testable otherwise methods in my import are not found.

@alper
Copy link

alper commented Jul 26, 2017

Does this mean delete the @testable part or delete the entire line?

Either way I'm getting lots and lots of unresolved imports.

@phynet
Copy link
Author

phynet commented Jul 30, 2017

Hello all, sorry that I haven't answered before but gist doesn't show alert notification for comments. I resolved deleting the line @testable and adding the bdrigin header .h file inside the test file...

@stuckj
Copy link

stuckj commented Aug 2, 2017

I'm unclear on the context here. If you're using @testable import YourProject (which I am) then it looks like it's in a swift file. In which case adding #import "Project-Bridging-Header.h" will lead to a syntax error since it's not valid swift. Also, as @hlung and @alper mentioned, you lose access to classes in the application module when you remove @testable. At least, like them, that's what I'm seeing.

@matzino
Copy link

matzino commented Aug 3, 2017

My Scenario: App contains mixed code (objC/Swift), UnitTest class is a swift file.

I import the "App-Bridging-Header.h" in my TestTarget Bridging Header (ObjC) and in my TestClass I remove the "@testable" so it looks like "import App". Then the Warning disappear and all seems to work well.

Source: Comments on the bug ticket: https://bugs.swift.org/browse/SR-3801

@phynet
Copy link
Author

phynet commented Aug 7, 2017

Maybe is not that clear the text I wrote long ago. I've updated the text :/ like @matzino commented, that was my solution as well.

@florieger
Copy link

Removing @testable in my test class leads to a lot of unresolved types, which are no longer imported from the "main" target.

For me the solution was much simpler, just go to the AppTest-Bridging-Header.h and add #import "App-Bridging-Header.h". I didn't touch the test class and kept the @testable.

@vegas3416
Copy link

@florieger - appreciate it. This worked for me. Just adding the #import "Bridging header.h file here" worked for me and didn't touch the @testable ` on my test class and all good.

@vegas3416
Copy link

Once I did this..I'm getting a module not found in my original bridging header file now. Warning or error went away in my test class but now my main bridging header is getting screwed up..any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment