| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This package contains an example program that demonstrates importing a Java library distributed as a Jar file into Swift and using some APIs from that library. It demonstrates how to:
This example wraps an open-source Java library implementing the Sieve of Eratosthenes algorithm for finding prime numbers, among other algorithms. To get started, clone that repository and build a Jar file containing the library:
git clone https://github.com/gazman-sdk/quadratic-sieve-Java cd quadratic-sieve-Java sh ./gradlew jar cd ..
Now we're ready to build and run the Swift program from Samples/JavaSieve:
swift run JavaSieve
The core of the example code is in Sources/JavaSieve/main.swift, using the static Java method SieveOfEratosthenes.findPrimes:
let sieveClass = try JavaClass<SieveOfEratosthenes>(environment: jvm.environment())
for prime in sieveClass.findPrimes(100)! {
print("Found prime: \(prime.intValue())")
}| Back | FazBrowse Home | New Git URL |