Jump to content
Rollo62

When will be binding to Swift libraries possible ?

Recommended Posts

Posted (edited)

Hi there,

 

it seems that Apple moves more and more from Objective-C to Swift,

especially for the new APIs, like RealityKit 2  https://developer.apple.com/documentation/realitykit.

 

That would mean Delphi / Firemonkey needs a way to bind with Swift, if no Objective-C might be available.

Has someone maybe checked about such Swift binding, and what pitfalls may be there ?

 

I would expect that Swift can handle more features, that cannot really converted to Delphi, but thats just my assumption.

Who could give more light to this ?

 

Edit:

I had an older post in the german DP, see here, as a kind of cross-post to this topic.

 

Edited by Rollo62

Share this post


Link to post
16 hours ago, Rollo62 said:

That would mean Delphi / Firemonkey needs a way to bind with Swift, if no Objective-C might be available.

 

There is QP report for that https://quality.embarcadero.com/browse/RSP-22944 

When will importing Swift frameworks be available, the is only that Embarcadero can tell. 

 

16 hours ago, Rollo62 said:

Has someone maybe checked about such Swift binding, and what pitfalls may be there ?

 

From what I can see, such Swift framework would have to be compiled in interop mode and Expose its API. Delphi is capable of importing Objective-C framework, so it is possible that @objc mode would suffice. If not there is unofficial @cdecl support, for Swift side.

 

https://forums.swift.org/t/best-way-to-call-a-swift-function-from-c/9829

 

This is not something I had need to explore, so this is all the information I can give.

  • Like 1

Share this post


Link to post
Posted (edited)

If the Swift framework does not support any explicit interop, it could be possibly wrapped and consumed through Objective-C library that can then be imported in Delphi https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c

 

If you need support for Swift frameworks now, this sounds like most viable option.

Edited by Dalija Prasnikar

Share this post


Link to post

I’ve been exploring this for my Delphi app which needs to support WidgetKit (iOS 13-style) Home Screen widgets. Getting the widget built and working with my app was easy enough but I’m struggling to force it to update when data changes as the WidgetKit API is swift only.

I’ve tried creating a native Obj-C static library which contains the bridging headers to call the swift code, and tried a swift static library with the @objc tags to expose the correct headers but Delphi just won’t see the exposed classes.

 

If I pull the libraries above into native ObjC apps they both work fine but Delphi can’t seem to see the classes exposed, even though they link into the app using the fake loader method.

 

I feel like I’m so tantalisingly close to getting this working so I’ll keep digging and post here if I get it working.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×