Exposing Swift methods to Generated Native Interface with @objc or @objcMembers annotations

36 views
Skip to first unread message

P5music

unread,
Sep 21, 2020, 4:59:10 AM9/21/20
to CodenameOne Discussions
I would like to add the import/export functions to my Codename App.
The way I need it, It can be done only with native code.
I have that native code in Swift language from the XCode Swift-native version of my app.
I would like to know if I can expose it  with the
@objc or @objcMembers
annotations for the Swift methods.
I mean, of course the generated files have to be like it is explained in Codename documentation, but I also would put Swift files in the native folder that contain the real methods (the "officially" interfaced obj-C methods call the Swift ones)
Does this make sense?
Thanks

Steve Hannah

unread,
Sep 21, 2020, 8:09:30 AM9/21/20
to codenameone...@googlegroups.com
You can create a swift framework in Xcode.  Then zip up the framework and put it in the native/ios directory, e.g. native/ios/MyFramework.framework.zip

I do this inside the WebRTC cn1lib I'm currently working on.  I needed to add build hints so that Clang would work with the swift modules properly:
ios.pods.build.CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES=YES
ios.pods.build.CLANG_ENABLE_MODULES=YES


Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/495f4544-9c31-4b59-8686-e2e57cee7e31n%40googlegroups.com.


--
Steve Hannah
Software Developer
Codename One

P5music

unread,
Sep 21, 2020, 4:56:59 PM9/21/20
to CodenameOne Discussions
Thank you.
The framework is made of  Swift code, but I wonder if the methods have to be exposed with the @objc annotation, and it is as usual on the Codename side, like the Generate Native Interface and so on, objective-C code included.
Regards

Steve Hannah

unread,
Sep 21, 2020, 5:05:57 PM9/21/20
to codenameone...@googlegroups.com
The native interface should be Objective-C like usual.  The Java talks only to this Objective-C layer.  Then to access your Swift framework, you use the usual rules for calling Swift from Objective-C.

You wouldn't put any swift files directly in the native/ios directory.  All Swift would be inside your framework, which you build, and zip, and place inside the native/ios folder.



--
Steve Hannah
Web Lite Solutions Corp.
Reply all
Reply to author
Forward
0 new messages