How to add Objective-C Bridging Header entry?

隐身守侯 提交于 2019-12-01 06:30:52

问题


I have a Swift project and have add a cocoapod, which is written in Objective-C. It has header and implementation files. From what I understand, to use/import these files into my Swift files, I need to add a bridging file.

I found this site describing how to do this manually, since the Objective-C files are already part of my project (from the cocoapod).

http://www.learnswiftonline.com/getting-started/adding-swift-bridging-header/

1.) Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results.

2.) Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there.

I don't have a Objective-C Bridging Header in that section and it doesn't appear you can add new entries there.

I'm using Xcode 7.3.1. Anyone have some idea how this should be done?


回答1:


Are you sure you looked at the correct Build Settings section, search with the keyword Swift compiler - General in the search field as describe below and then you can find it.




回答2:


You need to create the header file first. It is a regular Objective-C header file and should be named <Your app or framework name>-Bridging-Header.h. For any Objective-C headers you want Swift to know about add an import statement to the newly created header file. Then follow your previous steps. There is also a hidden header that gets created for you called <Your app or framework name>-Swift.h. If you need to access any Swift classes from an Objective-C file import this header.



来源:https://stackoverflow.com/questions/38468397/how-to-add-objective-c-bridging-header-entry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!