Let's assume a KMP Project which is set to have a Sample iOS app in which a KMP module's output framework is added as a dependency.
I am having a function sampleFuncForStringArrayList(names: ArrayList<String>) in KMP module which prints count and iterates and print ArrayList items.
When I call this function from the iOS sample app, I am getting index out of bound exception
because NSMutableArray count which is 2 in iOS app environment, has count as 24576 when received as ArrayList in KMP module.
This issue happens only with releaseFramework. debugFramework works fine.
//Swift
let namesStringList = NSMutableArray(array: ["Alice", "Bob"])
print("NSMutableArray COUNT : \(namesStringList.count)")
Main().sampleFuncForStringArrayList(names: namesStringList)
//Kotlin
public class Main {
public fun sampleFuncForStringArrayList(names: ArrayList<String>){
println("names.isNullOrEmpty() ${names.isNullOrEmpty()}")
println("names.count ${names.count()}")
names.forEach {
println("Hello $it")
}
}
}
Expected Output
NSMutableArray COUNT : 2
names.isNullOrEmpty() false
names.count 2
Hello Alice
Hello Bob
Actual Output:
NSMutableArray COUNT : 2
names.isNullOrEmpty() false
names.count 24576
CRASH
Sample Project ZIP: https://drive.google.com/file/d/1SgmW4hfeWaEeD3vcidnZ81Q9vMJsU9zJ/view?usp=sharing