Skip to content

Swift/Java interoperability example mixing Java & Swift code for a tiny Swing UI application

Notifications You must be signed in to change notification settings

DougGregor/celsius-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Swift/Java Interoperability Example: Swing Celsius -> Fahrenheit converter

This repository demonstrates Swift targets that mix Java and Swift source files, where Swift can be used to implement native methods declared in Java. It uses the swift-java package for Swift/Java interoperability.

How to run the example

First, set the JAVA_HOME environment variable to point to your Java installation.

Then, build the example with the following command:

swift build

Finally, run the example as follows:

java -cp .build/plugins/outputs/celsius-converter/JavaCelsiusConverterGUI/destination/JavaCompilerPlugin/Java -Djava.library.path=.build/debug learn.CelsiusConverterGUI

Exploring the source

The project only has two source files:

  • Sources/JavaCelsiusConverterGUI/learn/CelsiusConverterGUI.java: Java source code for the Java parts of this example, which originally came from a Java tutorial.
  • Sources/JavaCelsiusConverterGUI/CelsiusConverterGUI+Native.swift: Swift source code that implements the native Java methods for CelsiusConverterGUI.

Evolution of the example from Java to (mostly) Swift

The HEAD of the main branch contains the final version of the the program, with a mix of Java and Swift. Browse back in the git history for this project to see earlier states, starting with an all-Java implementation and then moving toward Swift implementations one commit at a time.

About

Swift/Java interoperability example mixing Java & Swift code for a tiny Swing UI application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published