objc2swift : Objective-C to Swift 转换工具

objc2swift : Objective-C to Swift 转换工具 - 敏捷大拇指 - objc2swift : Objective-C to Swift 转换工具

Try the online version at objc2swift.yahoo-labs.jp

Project Goal

We created objc2swift for our own good, to reduce the redundant task when rewriting Obj-C code to Swift.

Generally, rewriting process consists of two phases: first simply replacing the syntax from Obj-C to Swift, then adopting new features that are introduced to Swift.

objc2swift is aimed at reducing the first half of the process, so that we can focus more on the creative / intellectual work.

Please do not expect complete conversion.


  • Merges @interface and @implementation and create a single Swift class .
  • Converts properties, including those that have it's own getter/setter in the implementation.
  • Converts message-send to method-call.
  • Converts init-process such as [[MyThing alloc] initWithThing:...] into MyThing(thing: ...) .
  • Converts corresponding types and functions: NSInteger -> Int , NSLog -> print
  • ...and more!

Quick Start


Build jar:

[Bash shell] 纯文本查看 复制代码
$ git clone [url]https://github.com/yahoojapan/objc2swift.git[/url]
$ cd objc2swift
$ ./gradlew jar

Create an alias, and pass the Obj-C source files you want to convert.

[Bash shell] 纯文本查看 复制代码
$ alias objc2swift='java -jar /path/to/objc2swift/build/libs/objc2swift-1.0.jar'
$ objc2swift src/test/resources/sample.*


Install typesafe-activator , and run.

[Bash shell] 纯文本查看 复制代码
$ brew install typesafe-activator
$ cd web/
$ activator run

Access localhost:9000 , and there you are!

Developer's Guide

objc2swift is made with ANTLR . More detail coming soon.


This software is released under the MIT License, seeLICENSE.txt.