It works! Like science fiction. We have used J2Objc: A Java to iOS Objective-C translation tool and runtime.
On our recipe app we have a core part that converts imperial to the metric standard. This means that 1kg of flour is very different that 1kg of iron, so the code is extensive and has to deal with various string formatting issues.
For such component I was very reluctant to rewrite the entire thing in C or objective-c, as our android and server-side were already tested and working well with the Java version.
Our workflow while doing such task was:
- Keep trying to translate the Java code into objective-c. In our case we had issues with java.text.DecimalFormat, so we had to substitute that class with our own implementation. We also had issues with TXT files that we were reading from the classpath, so we just embedded them into the Java code, already formatted.
- After we got the whole project to export we used J2Objc to port the code in an extremely ugly format.
- We created a nicer objective-c interface that reads the ugly code and presents in a code that looks beautiful.
- Then we created a script that does the conversion for us and generates a static objective-c library as result. Awesome!
One codebase, well tested. Have fun and let me know about your adventure!