https://kotlinlang.org logo
#ios
Title
# ios
j

julien hamon

03/09/2022, 6:25 AM
Hi everybody i need your help to know how i could to see an entity in the kotlin shared module (iOSMain). For details i have a pods with his own entities (API and custom iOS pods) that i use with the expect/actual pattern. All work fine but i don’t arrive to see the attributes of my entity. exemple :
Copy code
@objc public class CourseImpl: NSObject, Decodable, Course {
    let objectID: String
    let status: Bool

    @objc init(objectID: String,
         status: Bool,
         title: String
    ) {
        self.objectID = objectID
        self.status = status
        self.title = title
       
    }
in iosMain
Copy code
actual fun search(words: String): List<Training> {
        val client = SearchClient()
        client.initializeWithAppId("", apiKey = "")
        client.searchWithText(text = words , indexName = "", callback = { response: List<Course> ->
            response.map { it.objectID // don't work }

        }.freeze() as (List<*>?) -> Unit)
        return listOf(Training(id = "1", name = "name1"), Training(id = "2", name = "name2"))
    }
could you help me to undestand ? thanks
s

Sam

03/09/2022, 1:16 PM
How is the Course interface defined? SearchClient is implemented in swift somewhere?
j

julien hamon

03/09/2022, 2:04 PM
it was a test so it’s something like this for the moment and yes for the second question
Copy code
protocol Course {
    var uuid: String { get }
}
s

Sam

03/09/2022, 7:32 PM
Anything you want to expose to Objc/Kotlin needs to have the @objc annotation or you can use the shortcut @objcMembers annotation on the class definition. https://www.hackingwithswift.com/example-code/language/what-is-the-objcmembers-attribute
j

julien hamon

03/10/2022, 3:05 AM
thanks i try but i understand that it works for method in a class but not for attributes
ok now it works with the protocol and the objective-c types. 🙂 thantks for your help
4 Views