1 Reply
      Latest reply: Jan 5, 2017 3:18 AM by eskimo RSS
      derell Level 1 Level 1 (0 points)

        I am attempting to write a unit test in swift that needs to access an Objective-C class.  I know that there is a file named "MyProject-Bridging-Header.h" already generated when I added swift files to my project, and a corresponding "MyProject-Swift.h" file.  For unit test files, there is also a file called "MyProjectTests-Bridging-Header.h" as well but I do not see a corresponding "MyProjectTests-Swift.h" file.  Therefore, I am not able to access Objective-C classes within unit test files that are written in swift. Any suggestions?

        • Re: Accessing Objective-C classes within a Swift unit test.
          eskimo Apple Staff Apple Staff (7,805 points)

          For unit test files, there is also a file called "MyProjectTests-Bridging-Header.h" as well but I do not see a corresponding "MyProjectTests-Swift.h" file.  Therefore, I am not able to access Objective-C classes within unit test files that are written in swift. Any suggestions?

          Huh?  There’s two directions to consider here:

          • Using Objective-C from Swift — To do this you include the relevant headers in your bridging header (xxx-Bridging-Header.h) and Swift will pick things up from there.

          • Using Swift from Objective-C — To do this, you include the xxx-Swift.h header in your Objective-C code.

          So, if you want to do the former you only need xxx-Bridging-Header.h.

          It sounds like you’ve added the relevant includes to your app target bridging header (MyProject-Bridging-Header.h) but not to your test target bridging header (MyProjectTests-Swift.h).

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"