11
22## SwiftJava - bridging Swift to a JavaVM
33
4- I know what you've been thinking.. what I really need is a way to bridge Swift
5- to Java but there are a number of use cases:
4+ I know you've been thinking.. "What I really need is a way to bridge Swift to Java"
5+ but there are a number of use cases:
66
771 . Making Java technologies such as JDBC available to macOS applications.
88
9- 2 . Giving Swift applications on Linux a portable user interface.
9+ 2 . Giving Swift applications on Linux a portable user interface using Swing .
1010
11- 3 . Making business logic in Swift available to Android apps.
11+ 3 . Making business logic in written in Swift available to Android apps.
1212
1313![ ] ( http://johnholdsworth.com/Linux.png ) ![ ] ( http://johnholdsworth.com/Android.png )
1414
1515SwiftJava is a Swift code generator along with a small framework of supporting code written in
16- the Xcode beta6 vintage of Swift 3.0. The starting point was Boris Bügling's talk on
17- [ Cross Platform Swift] ( https://realm.io/news/altconf-boris-bugling-cross-platform-swift/ ) .
16+ the Xcode beta6 vintage of Swift 3.0. The starting point was Boris Bügling's
17+ [ Cross Platform Swift] ( https://realm.io/news/altconf-boris-bugling-cross-platform-swift/ ) talk .
1818The code generator takes a java class, interface or package and generates Swift classes
1919that interface to corresponding Java methods using the Java Native Interface "JNI".
2020These generated methods on the corresponding Swift class look something like this:
@@ -34,7 +34,7 @@ These generated methods on the corresponding Swift class look something like thi
3434On macOS, this has been used to generate frameworks bridging the java.lang, java.util,
3535java.sql, java.awt and javax.swing packages along with the Apple specific additions
3636in the com.apple package. This makes the Java apis available with auto-completion in
37- the Xcode source editor. The final application can be a ".app" or command line utility
37+ the Xcode source editor. The final application can be a ".app" or a command line utility
3838which should be portable to Linux using the Swift Package manager. For Android, the code
3939generator can generate JNI code for a pair of interfaces from Java to Swift and from
4040Swift to Java saving the developer the chore of a lot of error prone manual stubbing.
@@ -45,7 +45,7 @@ To use, clone this project using the following command:
4545 git clone https://github.com/SwiftJava/SwiftJava.git --recurse-submodules
4646```
4747
48- This project contains the pre-generated java frameworks and an example macOS app using
48+ This project contains the pre-generated java frameworks, an example macOS app using
4949JDBC and a command line project with assorted AWT and Swing source. Development inside
5050Xcode uses the legacy "JavaVM" framework which requires Apple's JVM downloadable from:
5151
@@ -57,7 +57,7 @@ runloop. Use the JNI.background and JNI.run methods to achieve this in a portabl
5757
5858When using the Swift package manager to build code from the command line, install the
5959latest Oracle JDK and locate the directory containing the file libjvm.so or .dylib in
60- the jre. Use this directory to build using the following commands:
60+ the jre. Use the examples. directory to build using the following commands:
6161
6262``` Shell
6363 git clone https://github.com/SwiftJava/examples.git
@@ -108,7 +108,7 @@ You then use ./genswift.sh from this project to generate the Swift binding code:
108108 ./genswift.sh your.package your.jar
109109```
110110
111- This generates Swift classes and a third Java source src/org/genie/your_package/< YourApp >Proxy .java
111+ This generates Swift classes and a third Java source src/org/genie/your_package/YourAppProxy .java
112112that also needs to be included in your project. Consult the script genhello.sh and project
113113"swift-android-samples/swifthello" for details. The source "swift-android-samples/swifthello/src/main/swift/Sources/main.swift"
114114shows how to set this up with a native method called from the main activity.
@@ -144,12 +144,12 @@ shows how to set this up with a native method called from the main activity.
144144### Forward, Runnable, Listener, Adapter, subclass responsibility and Base classes.
145145
146146For every Java interface the code generator generates a Swift Protocol along
147- with a < Protocol >Forward class in instance of which conforms to the protocol and
147+ with a ProtocolForward class an instance of which conforms to the protocol and
148148can be used to message Java instances conforming to the interface/protocol.
149149
150150For the Runnable interface used in threading the converse needs to be possible
151151where Java code can call through to Swift code. This is performed using a Java
152- proxy class which has a pointer to the associated Swift object and a "native"e
152+ proxy class which has a pointer to the associated Swift object and a "native"
153153implementation of the "run()" method that calls through to Swift. On the Swift
154154side this is surfaced as the "RunnableBase" class which can be subclassed to
155155provide a Swift implementation of the "run()" method callable from Java.
@@ -176,11 +176,11 @@ of the subclasses such as java.awt.Canvas.paint(). A list of these methods needs
176176maintained in the code generator unfortunately. If one of these methods encountered
177177a Base class and Proxy is generated for the concrete class that can be subclassed.
178178
179- As these "Base" subclasses cant close over variable in your program you may want to
179+ As these "Base" subclasses can't close over variables in your program you may want to
180180have an initialiser to capture these instead. There is a bit of a standard dance
181- that needs to be performed. First instantiate the "Base" superclass and pass this
181+ that needs to be performed. First, instantiate the "Base" superclass and pass this
182182to the designated initialiser of your superclass. Due to the use of generics you'll
183- also be prompted to provide a null implementation of the required initialiser.
183+ also be prompted to provide a null implementation of the " required" initialiser.
184184
185185``` Swift
186186 init (imageProducer :ImageProducer) {
0 commit comments