Not able to call function of swift from Objective-C++ code

In Swift, my class is something looks like below

@objc public class DemoSDK: NSObject {

public static var shared = DemoSDK()

public func connect(delegate: DemoSDKDelegate?) {

I call a method from the swift like below (I am trying to write an equivalent objective-c++ code of below line)

DemoSDK.shared.connect(delegate: self)

How can I call swift file function from objective-c++ code? I already imported header and all related classes into objective-c++ class, also all the required class and methods are marked with @objc

(Note: class in swift do not have constructor or initializer)

DemoSDK *obj = [[DemoSDK alloc] init]; // Error 'init' is unavailable 

2 answers

  • answered 2018-11-08 06:18 Daniel

    Mark all public classes, protocols, initializers, functions and properties with @objc

  • answered 2018-11-08 06:21 Harshal

    Add getInstance Method in swift file:

    @objc public class DemoSDK: NSObject {
    private static var shared = DemoSDK()
    @objc public static func getInstance() -> DemoSDK {
      return shared
    @objc public func connect(delegate: DemoSDKDelegate?) {

    obj-C code :

    [[DemoSDK getInstance] connect: self];