[HN Gopher] Swift/Java interoperability tools and libraries
       ___________________________________________________________________
        
       Swift/Java interoperability tools and libraries
        
       Author : timsneath
       Score  : 70 points
       Date   : 2024-09-26 18:22 UTC (4 hours ago)
        
 (HTM) web link (twitter.com)
 (TXT) w3m dump (twitter.com)
        
       | microflash wrote:
       | This sounds useful. Here are links that actually load on my
       | phone.
       | 
       | - https://github.com/swiftlang/swift-java
       | 
       | - https://forums.swift.org/t/improving-swift-support-and-inter...
        
       | aaronbrethorst wrote:
       | Plus ca change:
       | https://developer.apple.com/library/archive/documentation/Co...
        
       | liuliu wrote:
       | PythonKit (from Swift) is underrated but immensely useful in
       | certain scenarios (i.e.: https://engineering.drawthings.ai/from-
       | iphone-ipad-to-mac-en...).
       | 
       | Hopefully JavaKit can find their usefulness too!
        
       | wiseowise wrote:
       | Will be wildly ironic if Apple pulls uno reverse card and eats
       | Kotlin on Android instead of the other way around.
        
         | airstrike wrote:
         | It will also be glorious
        
         | pjmlp wrote:
         | Except contrary to iOS, on Android the C and C++ surface is
         | very small, and calling JNI is a huge performance bottleneck.
         | 
         | Anyone that cares about performance on Android has to write the
         | userspace logic directly in Java or Kotlin, and use Android IPC
         | instead of JNI.
        
         | Alupis wrote:
         | Outside of Apple's ecosystem, is anyone using Swift?
         | 
         | Kotlin is growing in all areas, especially backend (being fully
         | embraced by Spring/Spring Boot et al).
        
         | daghamm wrote:
         | Kotlin-Java interoperability is at a completely different
         | level.
        
         | fidotron wrote:
         | This would happen in about five minutes if a SwiftUI port was
         | included.
         | 
         | Which ironically would be just like Flutter, totally bypassing
         | any native UI.
         | 
         | My gut feeling is both teams probably have a plan for
         | steamrollering the other in the event of anti monopoly measures
         | forcing each to accept the other store. I.e. it is conceivable
         | you could launch the Play Store on iOS and run a significant
         | proportion of Android apps through a compat layer.
        
         | jwells89 wrote:
         | If Swift were practical to use for Android app development, I
         | would absolutely do so. I enjoy writing Swift more than I do
         | Kotlin by a good measure and not having to wrestle with gradle
         | and proguard would be a nice bonus.
        
         | lukeh wrote:
         | This [1] is a good place to start!
         | 
         | [1] https://github.com/finagolfin/swift-android-sdk
        
       | glhaynes wrote:
       | Cool! One thing Swift is really (maybe uniquely?) strong at is
       | C/C++/Objective-C interop, including mixing "legacy" code with
       | Swift and even replacing it file-by-file with minimal ceremony.
       | Looks like this is aiming to bring a similar level of interop to
       | Swift<->Java.
        
       | koito17 wrote:
       | This gives me flashbacks to the Objective-C / Java bridge [1]
       | from over a decade ago. It makes me wonder how they are dealing
       | with memory management when Java objects are being used from
       | Swift (or Swift objects from Java). This was one (of various)
       | issues that made using the Cocoa Java bridge a bit unpleasant.
       | 
       | I guess Swift has a lot less run-time dynamism going on, so it
       | may not be too hard to translate Swift semantics to Java.
       | Definitely interested to see how this unfolds over the next year.
       | 
       | [1]
       | https://developer.apple.com/library/archive/documentation/Co...
        
         | favorited wrote:
         | > It makes me wonder how they are dealing with memory
         | management when Java objects are being used from Swift
         | 
         | It uses Swift macros to add a `JavaObjectHolder` property to
         | Swift types annotated with `@JavaClass`[0]. `JavaObjectHolder`
         | is a Swift class that takes a global JNI reference to the Java
         | object, and releases it when the holder is destroyed[1].
         | 
         | The result is that a codegen utility emits Swift structs[2]
         | that wrap the JNI values, and the JNI glue code for method
         | invocation is applied at compile-time when the macros are
         | expanded.
         | 
         | [0] https://github.com/swiftlang/swift-
         | java/blob/e7d7a217e37d49b...
         | 
         | [1] https://github.com/swiftlang/swift-
         | java/blob/main/Sources/Ja...
         | 
         | [2] https://github.com/swiftlang/swift-
         | java/blob/main/Sources/Ja...
        
         | lukeh wrote:
         | IIRC, the ObjC/Java bridge was first done at NeXT for
         | WebObjects around 1996... almost thirty years ago!
        
       | renewedrebecca wrote:
       | Oh, well that's cool!
        
       | trigganiggaz wrote:
       | It would be good to achieve interoperability with Taylor Swift,
       | indeed.
        
       ___________________________________________________________________
       (page generated 2024-09-26 23:01 UTC)