- 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
- 數據庫基礎教程(SQL Server平臺)
- Access 2016數據庫教程(微課版·第2版)
- Python廣告數據挖掘與分析實戰
- 新型數據庫系統:原理、架構與實踐
- 大數據Hadoop 3.X分布式處理實戰
- Apache Kylin權威指南
- 云原生數據中臺:架構、方法論與實踐
- 大數據治理與安全:從理論到開源實踐
- HikariCP連接池實戰
- Chef Essentials
- SQL Server深入詳解
- 菜鳥學SPSS數據分析
- Spring Boot 2.0 Cookbook(Second Edition)
- Google Cloud Platform for Architects
- Hands-On Java Deep Learning for Computer Vision