Open Source Swift and Cocos2d-x

I would like to announce a project that is in the works, Swift-CC, which is an open source project aimed at bringing the Swift the language to the Android platform, and potentially others as well.

The scope of this project is defined here. In a nutshell, this project project focuses on making the core Swift language cross platform. It does not include supporting SpriteKit, Foundation, UIKit, or any other proprietary Apple frameworks or APIs. The goal is to be able to develop applications using Swift as a language and run those applications on any platform. The first platform being worked on is Android.

The current status of the swift-cc project is that it can currently build Objective-C and Swift sources for Android using a custom toolchain. The toolchain makes use of LLVM-IR as a common representation so that it can compile Swift with the Apple Swift compiler into IR, and then use the LLVM compiler to convert the IR to Android object files.

In order to execute the compiled Swift code you need both an Objective-C and Swift runtime. Here is a related open source project to build an Objective-C runtime. This project currently builds but does not link into a static library due to some undefined references that I am working on. I have created a forum topic to discuss questions and solutions related to completion of the Objective-C runtime for use with the Swift-CC project.

Once the Objective-C runtime works, then implementation can begin on the minimal Swift runtime, which looks to be a handful of methods that are the glue between what the Swift compiler produces and the Objective-C runtime.

This project was originally started by looking into whether we could use Swift as a language to control Cocos2d-x. There is a set of bindings available here that allows you to build Cocos2d-x apps using Swift for iOS and Mac. There is also a complete sample game written using these bindings in the Cocos2d-x samples here. The logical next step is to port this effort to Android and other platforms by building an open source Swift toolchain and runtime.

Swift turns out to be a great choice for a language. It is fast, faster than Objective-C, but also since it depends on Objective-C it means you can subclass the bindings to Cocos2d-x. This means that you can extend the bindings using categories or by subclassing, and those changes will be instantly available to Swift. Swift is also better than C++ because it is easier to master, and is less error prone. It is also much faster than Lua or JS, making it an ideal choice as a language for Cocos2d-x.

This is a pretty major undertaking and so I heartily encourage anyone and everyone to take a look, give feedback, comments and suggestions using the forum, and also to fork and contribute as we move forward.

Thanks
Justin

2 Likes

yeah!
Looking forward to play with Swift + cocos2d-x.

Hi Justin,

For those new to Cocos2d-x and Swift, could you tell us what types of games you feel Swift-CC would be best suited for? With Swift at 1.0 do you feel there are types of games that one couldn’t make yet?

Right now with the Swift bindings, you can make pretty much any game where using Cocos2d-x would make sense. It only works for iOS and Mac right now, and you only need the bindings for that. Swift-CC is the open source Swift project that will enable the same Swift sources and bindings to run on the Android platform. Swift-CC is still in development.

Yeah right…

1 Like

Hi Justin,

Love that you are doing this, Swift is a really nice language (Obj-c is one of the worst I’ve ever used!). I’ve written in other places that I hope Apple will be active in spreading it to other platforms.

According the Wikipedia the licence for Swift is still “undecided”. I’m sure you know and consider it, I hope Apple make it open source but the simple fact it is still “undecided” makes me think it won’t be. What are your thoughts?

Also, I assume you’ve seen http://www.cocos2d-swift.org Perhaps you could consider making your language cross compatible with cocos2d-swift or get help from the cocos2d-swift team.

Hi GMTDev,

We don’t know what Apple is planning for Swift. Whether or not they will open source it or not remains to be seen.

I am aware of cocos2d-swift, I have not seen anything about Swift from them yet. I assume that the Objective-C and Swift runtimes would be interchangeable with ours. In that regard I am not trying to reinvent the wheel, the piece that I am focussing on is getting the Swift language features supported on Android. In order to do that I need a working recent (i.e. supports ARC, GCD, blocks etc.) Objective-C runtime, which I have not seen elsewhere yet, as such I have added an open source work in progress which I am working to complete, and perhaps others will contribute and or find it useful for their own projects.

Thanks
Justin

@mannewalis now, after Swift became open source, it’s time to refresh this project? Or maybe even create a new, with new ideas? http://forum.cocos2d-objc.org/t/cocos2d-pureswift/17597

Save your resources and don’t jump on every trend.
just fine tune the c++ engine , and the javascript wrapper , there are way many more js developers then swift .

@ricardo @mannewalis Any thoughts about this? Any news? I really interesting in this and I think many other devs too… Why you keep silence, can you you comment this?

Hey folks,

we have recently released Web Application Framework (Swift Express:https://github.com/crossroadlabs/Express) written in Swift for OS X and Linux. It’s simple, but still very powerful, inspired lot by Play Framework (https://www.playframework.com/) and Express JS (http://expressjs.com/).

Very curious to have some feedback of yours! Any feedback is highly appreciated.

Thanks,
Sofia Husak