Umar Ata
11/17/2020, 5:55 PMHi 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
alex009
11/24/2020, 12:11 PM@Throws(Exception::class)
fun feed(value: List<Double>) {
println("value: $value")
}
and from iOS side you will do:
do {
try feed(value: [
10000.54,
1234
])
}
catch {
print("error \(error)")
}
Umar Ata
11/24/2020, 1:33 PMalex009
11/24/2020, 1:41 PMlet dblArr: [KotlinDouble] = [2.3, 3.2]