https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
u

Umar Ata

11/17/2020, 5:55 PM
Copy code
Hi there,
I have a method in commonMain in SharedClass 
@Throws(Exception::class)
     fun feed(value: DoubleArray) {
..
}
and it inputs DoubleArray and I can pass that without any issues from Android Kotlin project but in iOS there is no such data type and I have
 let floatArray1 = Array(UnsafeBufferPointer(start: buf.floatChannelData![1], count:Int(buf.frameLength)))
but I cannot pass it to my method in commonMain
so for this I created another method in Kotlin in which first I convert the float array in swift to NSMutable String array then pass it to that method and in that method I create a DoubleArray and then initialise in ForEachIndex loop

@Throws(Exception::class)
    fun getDoubleArrayFromStringList(doubleArray: ArrayList<String>, printLog: Boolean?): DoubleArray {
        if (printLog == true) println("given array:$doubleArray")
        val signal = DoubleArray(doubleArray.count())
        doubleArray.forEachIndexed { index, str ->
                val doubleValue = (str.toDouble())
                signal[index] = doubleValue
        }
        if (printLog == true) println("converted array:${signal.contentToString()}")
        return signal
    }
Is there any easy solution for my problem
a

alex009

11/24/2020, 12:11 PM
hi! you can change signature in commonMain to:
Copy code
@Throws(Exception::class)
fun feed(value: List<Double>) {
    println("value: $value")
}
and from iOS side you will do:
Copy code
do {
    try feed(value: [
      10000.54,
      1234
    ])
  }
  catch {
    print("error \(error)")
  }
u

Umar Ata

11/24/2020, 1:33 PM
I can pass the double value directly that is okay from iOS But the problem is I have let dblArr = [2.3, 3.2] So if I pass it so it is throwing an error Cannot convert value of type '[Double]' to expected argument type [KotlinDouble]
a

alex009

11/24/2020, 1:41 PM
you can declare
let dblArr: [KotlinDouble] = [2.3, 3.2]
2 Views