Binding to Swift-based CocoaPods

I’ve been working on getting a Swift-based CocoaPod working in my MOE-1.3-based project - specifically, this one: https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-swift-push . Going through the helpful thread at Generating Java Bindings in 1.3 beta - How to do so? , I’ve been able to get to the point where I have the pods installed, Java classes generated, and an object read from a “sharedInstance” property.

However, I’ve run into what may be a problem with the library, but I want to double-check to make sure I’m not giving myself unnecessary work. Specifically, most of the classes from the BMSCore framework do not make the journey to Java. From what I’ve gathered, this seems to be likely because they don’t inherit from NSObject, and so don’t show up in the generated Objective-C header to be read by MOE. It seems like the solution to that is to essentially make a local fork of the Pod and modify each class I need to inherit from NSObject.

Since this seems at first to work, I’m going to go down this path. However: is this sane? Is there a better way to do what I’m trying to do?

Hi Jesse,

It is possible to create bindings for a Swift library, but the classes need to be available from Objective-C. We have a sample for this (using SimpleChart as the example):

To make a Swift class accessible from Objective-C, you can follow this guide from Apple:

For example, you might need to mark classes with the @objc annotation in Swift, if they are not picked up by the Swift -> ObjC header generator automatically.

Best Regards,
Gergely

1 Like