Swift for Kotlin Developers
Move from Kotlin to Swift through value semantics, optionals, Unicode text, protocols, and ARC. Complete 48 multi-file exercises, build a parcel desk across four steps, and port two Kotlin programs.
Kotlin and Swift side by side
The same program in Kotlin and in Swift, from the lessons of this course.
Bindings and Mutation
Kotlin uses val for a binding that cannot be reassigned and var for one that can. Swift spells those choices let and var, but collection behavior also depends on value semantics. A Kotlin val holding a mutable list can still mutate the list. Swift Array is a…
Kotlin1fun main() {2 val original = mutableListOf(2, 4)3 val alias = original4 alias.add(6)5 println(original.size)6}Swift1let original = [2, 4]2var copy = original3copy.append(6)4print(original.count, copy.count)Strings and Interpolation
Kotlin string templates use a dollar prefix; Swift interpolation uses a backslash and parentheses inside the literal. Swift String is a value type containing Unicode text. You can concatenate strings, test prefixes, and iterate over Characters without…
Kotlin1fun main() {2 val word = "echo"3 println(word.startsWith("ec"))4 println(word.repeat(2))5}Swift1let word = "echo"2print(word.hasPrefix("ec"))3print(String(repeating: word, count: 2))Switch and Patterns
Kotlin when can select a branch using values, ranges, or conditions. Swift switch similarly selects a matching case and can destructure tuples. A Swift switch must be exhaustive; a default handles the unmatched values of an open domain such as Int. Cases do…
Kotlin1fun location(x: Int, y: Int): String = when {2 x == 0 && y == 0 -> "origin"3 x == 0 || y == 0 -> "axis"4 else -> "plane"5}6fun main() { println(location(0, 0)); println(location(0, 5)); println(location(2, 3)) }Swift1func location(_ x: Int, _ y: Int) -> String {2 switch (x, y) {3 case (0, 0): return "origin"4 case (0, _), (_, 0): return "axis"5 default: return "plane"6 }7}8print(location(0, 0))9print(location(0, 5))10print(location(2, 3))Functions and Labels
Swift separates an external argument label from the parameter name used inside a function. By default the parameter name is also its call-site label. An underscore suppresses that external label, and a different word gives callers a more readable phrase.…
Kotlin1fun greet(person: String, from: String): String = "$from greets $person"2fun main() { println(greet(person = "Mina", from = "Jo")) }Swift1func greet(_ person: String, from sender: String) -> String {2 return "\(sender) greets \(person)"3}4print(greet("Mina", from: "Jo"))Dictionaries and Missing Keys
Kotlin Map lookup returns a nullable value when a key is missing. Swift Dictionary lookup similarly returns an Optional, even when the stored Value type itself is nonoptional. Use optional binding or a fallback when absence is valid. Swift also offers a…
Kotlin1fun main() {2 val ages = mapOf("Mina" to 12)3 println(ages["Mina"] ?: -1)4 println(ages.getOrDefault("Jo", 99))5 println(ages.size)6}Swift1let ages = ["Mina": 12]2print(ages["Mina"] ?? -1)3print(ages["Jo", default: 99])4print(ages.count)Structs and Independent Copies
A Kotlin data class still has reference semantics: assigning one variable to another shares the same instance, and copy must be requested explicitly. Swift structs are value types, so assignment creates an independent value automatically. Methods that change…
Kotlin1data class Point(var x: Int, val y: Int)2fun main() {3 val original = Point(3, 4)4 val reflected = original.copy()5 reflected.x = -reflected.x6 println("${original.x} ${reflected.x}")7}Swift1struct Point { var x: Int; let y: Int }2let original = Point(x: 3, y: 4)3var reflected = original4reflected.x = -reflected.x5print(original.x, reflected.x)
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsStarting Swift
5 lessonsText and Decisions
5 lessonsControl Flow
5 lessonsFunctions and Arrays
5 lessonsCollection Tools
5 lessonsValues and References
5 lessonsFailures and Abstraction
6 lessonsDesigning Types
6 lessonsParcel Desk Project
4 lessonsKotlin Ports
2 lessonsFrequently asked questions
Who is Swift for Kotlin Developers for?
For people who already write Kotlin and want to learn Swift. Each lesson starts from Kotlin you know and shows how Swift does the same thing, so you skip the beginner basics.
Do I need to know Swift already?
No. The course starts with your first Swift program. You need Kotlin basics: variables, conditions, loops, functions and collections.
How many lessons does Swift for Kotlin Developers have?
Swift for Kotlin Developers contains 48 interactive lessons you can complete at your own pace.
What does Swift for Kotlin Developers cover?
The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.
Is Swift for Kotlin Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.