ios 从 Swift 转换为 Objective-c 的工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33564214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tool to convert from Swift to objective-c
提问by developer82
I know most of the questions are about converting from objective-c to swift, but I'm looking for a tool that can convert a swift code to objective-c. When searching all I find is objective-c to swift.
我知道大多数问题都是关于从objective-c 转换为swift,但我正在寻找一种可以将swift 代码转换为objective-c 的工具。在搜索时,我发现的只是objective-c 到swift。
Yes - I know I can put swift code inside objective-c project with a bridge-header - that's not what I'm looking for.
是的 - 我知道我可以将 swift 代码放入带有桥头文件的 Objective-c 项目中 - 这不是我想要的。
I need a tool that converts swift code to objective-c code. Is there such thing?
我需要一个将 swift 代码转换为 Objective-c 代码的工具。有这种事吗?
采纳答案by imnosov
There is no such tools for converting Swift code to Objective-C. There are some reasons. One is because Objective-C is a semantic subset of Swift, i. e. Objective-C doesn't have any equivalent of some fundamental features of Swift such as Generics, Algebraic data types, Pattern matchingand other. Theoretically it is possible to make, but generated Objective-C code should be boilerplate and inefficient.
没有这样的工具可以将 Swift 代码转换为 Objective-C。有一些原因。一个是因为 Objective-C 是 Swift 的语义子集,即 Objective-C 没有任何等效于 Swift 的一些基本特性,例如泛型、代数数据类型、模式匹配等。理论上是可以的,但是生成的 Objective-C 代码应该是样板文件并且效率低下。