# TypeCasting Doubt and SqlDelight dependency error

**URL:** <https://discuss.kotlinlang.org/t/typecasting-doubt-and-sqldelight-dependency-error/14657>\
**Category:** Native\
**Created:** [October 15, 2019, 7:06am UTC](https://discuss.kotlinlang.org/t/typecasting-doubt-and-sqldelight-dependency-error/14657 "2019-10-15T07:06:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![callofdutybofan](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@callofdutybofan](https://discuss.kotlinlang.org/u/callofdutybofan)\
**Post date:** [October 15, 2019, 7:06am UTC](https://discuss.kotlinlang.org/t/typecasting-doubt-and-sqldelight-dependency-error/14657/1 "2019-10-15T07:06:10Z")

</div>

Hello,

I am new to Kotlin Multiplatform. I have two doubts regarding this language and platform.

1. I have created commonMain.kt . In this file I have created a function which returns array of string. But when I try to run this framework on iOS, this function returns array of type “KotlinArray”. Now if I have to typecast this “KotlinArray” in to [String] or NSArray in swift. How should I proceed?  
//here is the code for this function  
fun stringArrReturn(): Array {  
val arr = arrayOf(“a”,“b”,“c”)  
return arr  
}

2. it is regarding sqlDelight library…I wrote all possible code related to sqlDelight in common main.kt . I don’t get any error while compiling this.  
But When I try to run it on iOS and try to add in database I get this error -  
“ **kotlin.Error, kotlin.RuntimeException and subclasses aren’t propagated from Kotlin to Objective-C/Swift.** ”

//code for SqlDelight  
@ThreadLocal  
object CommonDatabase {  
var driver: SqlDriver? = getDriver()  
val database: Database by lazy {  
println()  
print(“getting driver”)  
Database(driver!!)  
}

```
private val observers: MutableMap<Int, Query.Listener> = mutableMapOf()

fun addTodo(title: String, completed: Boolean) {
    println()
    println("add todos... query")
    val completedNum = if (completed) 1L else 0L
    database.databaseQueries.insert(title, completedNum)
}

fun observeTodos(id: Int, onChangeCallback: (List<Todo>) -> Unit) {
    println()
    println("observe todos... query")
    if (observers.containsKey(id)) {
        throw RuntimeException("Already observing with id $id")
    } else {
        val listener = object : Query.Listener {
            override fun queryResultsChanged() {
                onChangeCallback(database.databaseQueries.selectAll().executeAsList())
            }
        }
        observers[id] = listener
        database.databaseQueries.selectAll().addListener(listener)
    }
}

fun stopObservingTodos(id: Int) {
    println("stop observing... query")
    observers[id]?.let {
        database.databaseQueries.selectAll().removeListener(it)
    }
}

fun deleteAll() {
    println("delete items")
    database.databaseQueries.deleteAll()
}

```

}

Thank you.

---

<div class="post-metadata">

**Author:** ![Artyom.Degtyarev](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@Artyom.Degtyarev](https://discuss.kotlinlang.org/u/Artyom.Degtyarev)\
**Post date:** [October 15, 2019, 9:09am UTC](https://discuss.kotlinlang.org/t/typecasting-doubt-and-sqldelight-dependency-error/14657/2 "2019-10-15T09:09:04Z")

</div>

Hello, @callofdutybofan!

1. You can use `listOf` instead. [Here](https://github.com/JetBrains/kotlin-native/blob/master/OBJC_INTEROP.md) one can find an exact list of Kotlin-Swift concepts translation. This document states, that Kotlin analogue of the `NSArray` is the `List`.
2. This issue looks slightly more complex. Please provide full stacktrace, and we’ll see what can be done.

---

<div class="post-metadata">

**Author:** ![callofdutybofan](https://avatars.discourse-cdn.com/v4/letter/c/8e7dd6/32.png) [@callofdutybofan](https://discuss.kotlinlang.org/u/callofdutybofan)\
**Post date:** [October 15, 2019, 10:13am UTC](https://discuss.kotlinlang.org/t/typecasting-doubt-and-sqldelight-dependency-error/14657/3 "2019-10-15T10:13:45Z")

</div>

Thanks a lot for quick reply. Thank you for the link. In second query I was following this tutorial - [Kotlin Multiplatform for Clean Architecture - inovex GmbH](https://www.inovex.de/blog/kotlin-multiplatform-for-clean-architecture/) - it was issue from my side. I went through the tutorial once again and managed to resolve it.  
Thank you.
