Call an Objective-C class from a Swift test file

后端 未结 1 1782
暗喜
暗喜 2021-01-18 08:26

I\'m working on implementing unit tests. The original project was written in Objective-C.

I created a new Test Target that is written in Swift.

How do I call

相关标签:
1条回答
  • 2021-01-18 08:54

    You need to create bridging header and add Objective-C file in to that. Create a bridging header YourProductName-Bridging-Header.h and then import HomeViewControllerin bridging header.

    To import Objective-C code into Swift from the same target

    In your Objective-C bridging header file, import every Objective-C header you want to expose to Swift. For example:

    #import "XYZCustomCell.h"
    #import "XYZCustomView.h"
    #import "XYZCustomViewController.h" 
    

    In Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting under has a path to the bridging header file. The path should be relative to your project, similar to the way your Info.plist path is specified in Build Settings. In most cases, you should not need to modify this setting.

    Below are some resources which can help you

    1. Using Swift with Objective-C
    2. Answer to another stack overflow qustion
    3. How to use Objective-C in swift
    0 讨论(0)
提交回复
热议问题