Skip to content

jextract/jni: Support Foundation value types in protocol callbacks #943

Open

Description

@teamhimeh

Problem

JNI protocol callbacks reject Foundation value types even though the Java-facing method signatures already support them. As a result, a Swift protocol accepting or returning Data, Date, URL, or UUID cannot be implemented as an ordinary Java callback.

Example

import Foundation

public protocol IdentityCallback {
  func transform(_ value: UUID) -> UUID
}

public func apply(_ callback: some IdentityCallback, _ value: UUID) -> UUID {
  callback.transform(value)
}

With enableJavaCallbacks enabled, Java should be able to implement the protocol using the existing java.util.UUID representation:

IdentityCallback callback = value ->
    java.util.UUID.fromString("87654321-4321-8765-cba9-876543210fed");

java.util.UUID input =
    java.util.UUID.fromString("12345678-1234-5678-9abc-def012345678");
java.util.UUID result = MySwiftLibrary.apply(callback, input);

The callback bridge would need to convert the Swift argument into a Java UUID and the Java result back into Swift. Data, Date, and URL could use their existing generated wrapper classes.

Reference workaround implementation: qoncept#5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:jextractIssues related to jextract-swift

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions