EDIT: Solved ✅
Hey I have an extension function for iOS where I convert
NSData
to
ByteArray
. However when trying to call it from Swift, it doesn’t show up in the function list suggestions
This function has been set in the iOS source set and I’ve re-compiled both projects again and still not working
Could it be that I might not be thinking of something that needs to be done aside from creating the function and compiling?
robercoding
07/28/2024, 7:13 AM
The function on iOS source set
Copy code
public fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt()).apply {
usePinned {
memcpy(it.addressOf(0), this@toByteArray.bytes, this@toByteArray.length)
}
}
robercoding
07/28/2024, 7:14 AM
The call
NSData(data: imageData).toByteArray()
robercoding
07/28/2024, 7:19 AM
Huh, the function seems to be generated but its receiver is not
NSData
specifically.. Guess it’s expected, but could it be that is not accessible specifically from
NSData
?
robercoding
07/28/2024, 7:21 AM
Well,
Data
type doesn’t seem to be working neither
robercoding
07/28/2024, 7:23 AM
Ah I got it, so it generates a “static class” that you can use to invoke “normal” functions. It doesn’t generate extension functions in Swift
robercoding
07/28/2024, 7:24 AM
I was trying to call it as an extension function 😄