Kotlin and Swift have very similar kinds of collections and can be mapped between each other.
Kotlin | Swift |
---|---|
List | Array |
MutableList | NSMutableArray |
Array | KotlinArray |
Set | Set |
Map | Dictionary |
MutableMap | NSMutableDictionary |
In Kotlin:
fun getList(): List<Int> {
return listOf(1,2,3)
}
fun getArray(): Array<Int> {
return arrayOf(1,2,3)
}
fun getMap(): Map<String, Int> {
return mapOf("a" to 1, "b" to 2)
}
fun getSet(): Set<Int> {
return setOf(1,1,2)
}
fun set(collection: List<Int>){
println(collection)
}
In Swift:
let a: Array<KotlinInt> = CollectionsKt.getList()
let a2: KotlinArray<KotlinInt> = CollectionsKt.getArray()
let d: Dictionary<String, KotlinInt> = CollectionsKt.getMap()
let s: Set<KotlinInt> = CollectionsKt.getSet()
CollectionsKt.set(collection: [1,2,3])