Objective-C Bridging Header not getting created wi

2019-01-13 12:57发布

I am trying to add objective-c libraries to my Swift 3 project (Xcode 8 IDE). But objective c interface header is not getting generated automatically. I tried to add bridging header manually but showing linking error saying bridging header .h is not found. Any help would be appreciated :)

4条回答
老娘就宠你
2楼-- · 2019-01-13 13:16

Objective C Header file creation steps

  1. File -> New -> File -> Header File

  2. Name your Header file like this yourAppName-Bridging-Header

  3. Now click on your Project -> Build Settings

  4. Change from Basic to All

  5. Search Bridging

  6. You will get the search result as shown in the below image

enter image description here

after Adding

enter image description here

  1. In that double click the right of Objective-C Bridging Header and enter as follows

    eg, yourAppName/yourAppName-Bridging-Header.h

  2. You need to import as follows

enter image description here

  1. Thats All

Happy Coding :)

Note:
The header file should be directly inside project, ie. it should not be created inside any subfolder

查看更多
劫难
3楼-- · 2019-01-13 13:17

Try clearing or renaming your DerivedData folder, then restart Xcode8. There must be some cached Xcode7 files in there remaining.

Worked for me

查看更多
放荡不羁爱自由
4楼-- · 2019-01-13 13:27

Here the solution for the issue.

  • Create a new header file and name it like "your project name-Bridging-Header.h". The file must be saved to your project folder
  • Select your xcode project -> select your build target -> select build settings -> click the "all" option at the top -> search for Swift Compiler - General
  • Select Objective-C Bridging Header item and double click on its value field (right side of the same row). One popup would appear and there you can enter your bridging header file path (Follow the below steps to provide header file path).
  • Open finder and drag and drop your bridging header file to the popup. Now it will create an absolute path for bridging header. To make relating path, you can give the path as $(PROJECT_DIR)/$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h

  • Click outside for the value get saved. Done!! Now you can import your Objective-C libraries (eg. #import "SVProgressHUD.h") to bridging file and start using it in your swift project.

Hope this would be helpful to someone. :)

查看更多
女痞
5楼-- · 2019-01-13 13:31

In the case of multiple targets, make sure the swift classes are members of that target, or else the file will not be generated.
Xcode 8.3

查看更多
登录 后发表回答