Quick and dirty Obj-C to Swift conversion script?

46 views
Skip to first unread message

Jens Alfke

unread,
Mar 29, 2015, 4:04:15 PM3/29/15
to swift-l...@googlegroups.com
Anyone know of a tool that helps with translating Objective-C source code to Swift? Not a full translator that emits valid Swift code (although that would be amazing!), just a script that runs a bunch of regexps to do the annoying grunt-work. Stuff like changing “@implemention Foo” to “class Foo {“; changing “- (void) bar” to “func bar( )”; stripping semicolons; etc.

I’ve written a few such tools in the past (one for C++-to-Java, one for Python-to-Ruby) and they’re big time-savers when porting code.

(I did a quick Google search but all I found were guides on how to manually translate.)

—Jens

Jens Alfke

unread,
Apr 7, 2015, 2:09:52 AM4/7/15
to swift-l...@googlegroups.com


On Sunday, March 29, 2015 at 1:04:15 PM UTC-7, Jens Alfke wrote:
Anyone know of a tool that helps with translating Objective-C source code to Swift? Not a full translator that emits valid Swift code (although that would be amazing!), just a script that runs a bunch of regexps to do the annoying grunt-work. Stuff like changing “@implemention Foo” to “class Foo {“; changing “- (void) bar” to “func bar( )”; stripping semicolons; etc.

It didn't seem to exist, so I went ahead and wrote one today:

It's an awful hack written in Ruby using dozens of unreadable regexes, but it works. It absolutely does not produce compilable code, but it converts a ton of stuff including method declarations, initializers, message-sends and variable declarations. I haven't started using it in earnest yet, but it should drastically cut down the time needed to port code.

Feel free to publicize this on your Twatters and Reedits and whatever other new-fangled BBSs you kids use nowadays!

--Jens
Reply all
Reply to author
Forward
0 new messages