Hi! Someone can help me to understund how can i ca...
# multiplatform
f
Hi! Someone can help me to understund how can i call a swift function from my ios kotlin multiplatform code? i added
Copy code
external fun swiftWriteLine(path: String, line: String)
and then in the swft folder i added a file with
Copy code
public static func swiftWriteLine(path: String, line: String) {
    print("Hola desde Swift!")
}
But its not working... it says external function <root>.swiftWriteLine must have @TypedIntrinsic, @SymbolName, @GCUnsafeCall or @ObjCMethod annotation where i have to add these anotations?
j
Kotlin only interops with Objective-C. Swift code will need the
@objc
attribute for Objective-C/Kotlin compatibility.
f
@Jeff Lockhart Should I add the @objc before the function name in the Swift function?
j
Yes, similar to an annotation in Kotlin. See examples.
f
Screenshot 2023-09-13 at 4.31.45 PM.png,Screenshot 2023-09-13 at 4.31.53 PM.png,Screenshot 2023-09-13 at 4.32.00 PM.png
@Jeff Lockhart thanks for the quick help. unfortunately it's still not working. any clue?
j
You should create a
.def
file to define the cinterop that will generate the Kotlin bindings to the Objective-C (Swift) code. Read the docs here and here for details.
f
will do. thanks!