- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 220字
- 2021-07-02 14:45:13
Importing Objective-C in Swift
This is usually how we discover the interoperability layer. An existing Objective-C code base is getting upgraded to Swift and you need to expose existing Objective-C classes to your new Swift code.
In Swift, all of your classes are available in the current module, depending on their access control scopes. In Objective-C, one developer need is to import a header through the #import "MyClass.h" directive or the module through @import ExternalLibrary. In order to expose your classes to Swift, you'll need to use a bridging header. Its responsibility is to expose only the classes you wish to the Swift compiler.
The bridging header is a header file that contains all of the import statements of the libraries and classes that are available to Swift. Once exposed this way, those classes are automatically available in all of the Swift code.
Let's set up a project for bridging:
- Add a header file to your project; call it Bridging-Header.h, for example
- In your Project Build settings, set SWIFT_OBJC_BRIDGING_HEADER to the path relative to your project root to your Bridging-Header.h file
- Add the required imports to your header
- LibGDX Game Development Essentials
- 從零開始學Hadoop大數據分析(視頻教學版)
- Architects of Intelligence
- 算法與數據中臺:基于Google、Facebook與微博實踐
- 達夢數據庫性能優化
- INSTANT Cytoscape Complex Network Analysis How-to
- 數據庫技術實用教程
- 云數據中心網絡與SDN:技術架構與實現
- 數據庫技術及應用
- 數據修復技術與典型實例實戰詳解(第2版)
- 數據分析思維:產品經理的成長筆記
- 大數據測試技術:數據采集、分析與測試實踐(在線實驗+在線自測)
- 數據中心UPS系統運維
- R數據挖掘實戰
- 反饋:化解不確定性的數字認知論