swiftlang / swiftlang/swift-java

Unable to use Swift function that returns String on Java side

Open
#216 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

I'm using jextract-swift to create Java Classes for the Sources/MySwiftLibrary/SwiftKitSamleApp for the sample SwiftKitSampleApp.

I created the following function just to test something in HelloJava2Swift.swift

public func retrieveToken() -> String {
  return "test"
}

But when I try to do the following in MySwiftLibraryTest.java

@Test
    void call_retrieveToken() {
        MySwiftLibrary.retrieveToken();
        assertNotNull(MySwiftLibrary.retrieveToken$address());
    }

It gives the following error

Image

I'm probably forgetting something important.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the retrieveToken declaration in Sources/MySwiftLibrary/HelloJava2Swift.swift and the generated call in MySwiftLibraryTest.java. Reproduce the failure using the jextract-swift-generated MySwiftLibrary classes, then determine what prevents a Swift String return from being called on the Java side. Done means the Java test can call retrieveToken() and assert that retrieveToken$address() is not null.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.