使用Xcode生成的接口了解Objective-C与Swift的互操作性
Did you know that Xcode has a limited built-in Objective-C → Swift converter?
您是否知道Xcode具有有限的内置Objective-C→Swift转换器?
Typically, for every Objective-C class, we have two files: a header file and an implementation file. The header file (or interface) contains the public properties, methods, and functions of the class, while the implementation file (as the name implies) contains the internal implementation details of the class methods and functions as well as private properties, methods and functions.
通常,对于每个Objective-C类,我们都有两个文件:标头文件和实现文件。 头文件(或接口)包含类的公共属性,方法和函数,而实现文件(顾名思义)包含类方法和函数的内部实现详细信息以及私有属性,方法和函数。
In Swift the header and the implementation files are combined into a single .swift file. The access scope if the properties, functions and mrthods is completely defined by access specifiers with the default access level being “internal”.
在Swift中,标头和实现文件被组合为单个.swift文件。 属性,功能和方法的访问范围完全由访问说明符定义,默认访问级别为“内部”。
Excited to dig deeper?
兴奋地深入研究?
To see this automatic converter in action, please download this sample Xcode project and open the Animal.h file.
要查看此自动转换器的运行情况,请下载此示例Xcode项目并打开Animal.h文件。
To see the converter in action just build your project (⌘ + B).Note: the generated interface files are only updated only when you rebuild your project.
要查看运行中的转换器,只需构建您的项目(⌘+ B) 。注意:仅当您重建项目时,才会更新生成的接口文件。
Here is the Generated Swift Inerface for the Animal.h file
这是Animal.h文件的生成的Swift Inerface
One more small detail, you can also convert your Swift files to Objective-C.
还有一个小细节,您还可以将Swift文件转换为Objective-C。
结论 (Conclusion)
This feature helps us better understand how Xcode imports any given Objective-C declaration in Swift. When using Swiftify to gradually migrate your projects, you can use this feature to understand any nuances in the syntax of declarations. But as you have already seen this method converts only the function declarations and not the code inside the functions and methods.
此功能有助于我们更好地了解Xcode如何在Swift中导入任何给定的Objective-C声明。 使用Swiftify逐步迁移项目时,可以使用此功能来理解声明语法中的任何细微差别。 但是,正如您已经看到的那样,此方法仅转换函数声明,而不转换函数和方法中的代码。
- 在VB中如何直接使用CLSID生成接口实例
- 使用mex C生成MATLAB的股票数据分析接口
- Objective-C学习笔记第七章深入了解Xcode
- 个人对List接口中的iterator方法的使用了解
- Manifest.xml中删除了『存储/修改删除SD卡中的内容』和『手机通话/读取手机状态和身份』权限,但生成apk安装软件时仍提示 允许应用程序了解或使用这两个权限
- 在一个工程中同时使用Swift和Objective-C
- 深入了解android平台的jni---使用宏定义精简JNI接口函数名称
- 教你深入了解Java中接口的使用
- xcode 4.2使用方法初探--第一个objective-c程序
- [技巧]使用Xcode集成的HeaderDoc自动生成注释和开发文档
- 在同一个项目中使用Swift 和 Objective-C
- 在项目中同时使用Objective-C和Swift
- 在Objective-C 中使用字符生成NSArray、NSDictionary、NSNumber
- OC基础回顾(六)了解和使用Xcode
- 在xcode 6.4 中使用swift和object-c混合编程,同时通过cocoapods进行管理的一些问题和解决办法
- 使用mex C生成MATLAB的股票数据分析接口
- Objective-C学习-如何使用Xcode4.2和Interface Builder创建自己第一个界面产品
- 在Xcode中使用C++与Objective-C混编
- 使用Uncrustify在Xcode中格式化Objective-C代码
- [技巧]使用Xcode集成的HeaderDoc自动生成注释和开发文档