Quick and dirty Obj-C to Swift conversion script?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Quick and dirty Obj-C to Swift conversion script?

Jens Alfke
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

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/AC1DB383-1B7F-42DD-8DA3-5ECA8E7F8A70%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Quick and dirty Obj-C to Swift conversion script?

Jens Alfke


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:
    https://github.com/snej/swiftier

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

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/abbb80d6-1bc5-4c36-a41a-4d678beeb0dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.