Hello All, Need a little help. There is a custom m...
# multiplatform
u
Hello All, Need a little help. There is a custom method written in Swift
fun static sendToTailor(name : String)
. I need to call this method in IOS main of KMM, how can I do that ?
s
You'll need to add/use cinterop and write a Obj-C wrapper for it. With this particular method, using the
@objc
annotation in your swift code should suffice for swift to write all the necessary wrappers.
u
@streetsofboston I have written this
Copy code
import Foundation

@objc class TailorBridge: NSObject {
    @objc static func sendToTailor(name: String, payload: [String: Any]) {
        print("Name: \(name), Value: \(payload)")
    }
}
Copy code
actual object TailorBridge {
    actual fun sendToTailor(
        name: String,
        payload: Map<String, Any>
    ) {
        val nsDictionary = payload.toNSDictionary()
        TailorBridge().sendToTailor(name, nsDictionary)
    }
}
But in actual its not able to resolve
Error -> error: Unresolved reference:
s
You created the Obj-C wrappers through the
@objc
annotations. You'll still need to add and configure KMP's cinterop functionality so that these Obj-C wrappers are visible/accessible by KMP.
thank you color 1
u
Still not able to, may be I am missing some configuration