Live data from Hacker News

Swift-X tool to cross compile Swift and Objective-C(++) code to Android

swift-x.org

11–20 of 27 posts

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#12
post #8

Earlier quoted context omitted.

Another viable — and possibly more enjoyable — approach would be to use C# for the full stack, irrespective of platform. See http://xamarin.com

No offense against C# (I like the language) but Xamarin is a commercial product https://store.xamarin.com/ which makes you dependent on Xamarin. Xamarin is definitely more advanced and I guess you can also do cross compiling UI apps. But before going the Xamarin road I would look more into QT.

> But before going the Xamarin road I would look more into QT.

Which is also commercial, unless you plan to release an open source app.

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#13
post #5
post #4

Earlier quoted context omitted.

You can't just take a Swift app for iOS and compile it for Android, sure. But this could be useful for people who enjoy Swift, and want to reuse blocks of logic from their iOS app to an Android port. I'm wondering though, I thought Swift compiled down to code that uses things like the Foundation framework (NSString etc), which would also be missing on Android. It would be hard to do anything without these classes, wo…

There are several independent open-source implementations of Foundation like GNUStep and Cocotron. Once you have the Obj-C runtime and cross-compiler working, porting either of those to Android should be fairly simple... But I suspect that Swift may have dependencies on new or recent Foundation features which could be missing from the open-source versions (for understandable reasons, they lag behind Apple by several…

In what concerns GNUStep, has it improved the situation of a partially supported NeXTStep and Cocoa around 10.4?

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#14
post #12

Earlier quoted context omitted.

No offense against C# (I like the language) but Xamarin is a commercial product https://store.xamarin.com/ which makes you dependent on Xamarin. Xamarin is definitely more advanced and I guess you can also do cross compiling UI apps. But before going the Xamarin road I would look more into QT.

> But before going the Xamarin road I would look more into QT. Which is also commercial, unless you plan to release an open source app.

Qt has been available under the LGPL for several years now.

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#15

When I wanted to code a foundation of reusable code for different devices I would either do it like Dropbox and use C++ as the most common layer http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cros... or use Javascript (which I can also use for web pages) for the program logic like described here http://www.skyscanner.net/blogs/developing-mobile-cross-plat... Also interesting http://kivy.org allows you to use…

Another option that I'm currently using for a prototype at work is Java (or any JVM language) via RoboVM http://www.robovm.org - it works similar to Xamarin so it compiles Java bytecode to LLVM to a native binary. The advantage over Xamarin is, that it uses the Apache 2 license so doesn't require hefty license fees or a subscription and you are independent. RoboVM will be released in the next couple of month in version 1.0 and it works very very well.

My current prototype uses Java for all the backend / business logic (data base communication, file access, network access, threading etc.) and it communicates via a JavaScript bridge to a WebView UI layer for which I have targets for iOS (RoboVM), desktop (JavaFX), HTTP server (Jetty) and later possibly Android. All from a single Java code base which shares large amounts of code between the platforms.

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#16

When I wanted to code a foundation of reusable code for different devices I would either do it like Dropbox and use C++ as the most common layer http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cros... or use Javascript (which I can also use for web pages) for the program logic like described here http://www.skyscanner.net/blogs/developing-mobile-cross-plat... Also interesting http://kivy.org allows you to use…

There's also j2objc, another interesting tool for creating a common layer for iOS and Android apps.

https://github.com/google/j2objc

I'm playing with it for a personal project, and as long as you're not too adventurous with your use of the JRE, it produces pretty usable Objective-C code.

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#17
post #12

Earlier quoted context omitted.

> But before going the Xamarin road I would look more into QT. Which is also commercial, unless you plan to release an open source app.

Qt has been available under the LGPL for several years now.

For iOS?

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#18
post #12

Earlier quoted context omitted.

> But before going the Xamarin road I would look more into QT. Which is also commercial, unless you plan to release an open source app.

Qt has been available under the LGPL for several years now.

Static linking for iOS generally means an Qt enterprise license for proprietary / closed applications.

Obviously every situation is unique.

Re: Swift-X tool to cross compile Swift and Objective-C(++) code to Android

#20
FWIW I took a recent look at porting the Apple Objective-C runtime to Linux (with the vague idea that if Apple open source Swift, it might be easier to get it working with their own runtime rather than the GNUstep one).

One nice thing about clang is that there's no problem outputting Objective-C code that uses the Apple runtime on other platforms: just use -fobjc-runtime=macosx. The catch is that because class, protocol, etc definitions are just data, you need a way to get notified by the runtime linker when an object is mapped into the process address space. (You could scan the current address space at startup, but that makes it difficult to support dynamic loading, although probably not impossible now that I think about it. I thought I was nearly there with ld.so audit interface, but audit modules are loaded into their own namespace, so you can't easily communicate with the global libobjc.)

Post reply on HN