Skip to content

Latest commit

 

History

History
50 lines (40 loc) · 1.08 KB

Collections.md

File metadata and controls

50 lines (40 loc) · 1.08 KB

Collections

Kotlin and Swift have very similar kinds of collections and can be mapped between each other.

Explanations

KotlinSwift
ListArray
MutableListNSMutableArray
ArrayKotlinArray
SetSet
MapDictionary
MutableMapNSMutableDictionary

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])

Table of contents