Swift for TypeScript Developers
Move from TypeScript to Swift through optionals, value semantics, Unicode, protocols and ARC. Complete 48 multi-file exercises, build a parcel desk in four stages and port two complete TypeScript programs.
TypeScript and Swift side by side
The same program in TypeScript and in Swift, from the lessons of this course.
Bindings and Mutation
TypeScript's const prevents reassignment of the binding. It does not freeze the referenced array. A readonly view is a compile-time restriction, and another mutable alias can still change the same object. The restriction is shallow: a readonly property…
TypeScript1export {};2const pending = ["upload", "index"];3const alias = pending;4alias.length = 0;5console.log(pending.length, alias.length);Swift1import Foundation2let pending = ["upload", "index"]3var copy = pending4copy.removeAll()5print(pending.count, copy.count)Strings and Interpolation
TypeScript template literals embed values with ${...}. Swift uses backslash-parenthesis interpolation inside an ordinary string literal. Both forms create strings from values; neither is a request to evaluate arbitrary source text. Use Swift's hasPrefix to…
TypeScript1export {};2const folder = "cache";3const path = `${folder}/image`;4console.log(path.startsWith("cache/"));5console.log(".".repeat(3));Swift1import Foundation2let folder = "cache"3let path = "\(folder)/image"4print(path.hasPrefix("cache/"))5print(String(repeating: ".", count: 3))Switch and Patterns
A JavaScript switch may fall through unless a case exits or uses break. Swift finishes a matched case without an implicit fallthrough. Swift also requires exhaustive handling, so switching over an unrestricted integer or string generally needs default.
TypeScript1export {};2function axis(x: number, y: number): string {3 if (x === 0 && y === 0) return "origin";4 if (x === 0) return "vertical";5 return "other";6}7console.log(axis(0, 9));Swift1import Foundation2func axis(_ x: Int, _ y: Int) -> String {3 switch (x, y) {4 case (0, 0): return "origin"5 case (0, _): return "vertical"6 default: return "other"7 }8}Functions and Labels
TypeScript parameters are normally positional, or callers pass an options object to make meaning explicit. Swift separates an external argument label from the parameter name used inside a function. An underscore suppresses the external label. A label is…
TypeScript1export {};2function mark(text: string, options: {prefix: string}): string {3 return options.prefix + text;4}5console.log(mark("draft", {prefix: "!"}));Swift1import Foundation2func mark(_ text: String, with prefix: String) -> String { prefix + text }Dictionaries and Missing Keys
A TypeScript Map.get returns a value or undefined; a Swift dictionary subscript returns an optional because the key may be absent. JavaScript Map assignment aliases the same map. Swift dictionaries are values, so assigning a dictionary produces an…
TypeScript1export {};2const flags = new Map<string, boolean>([["cache", true]]);3flags.delete("cache");4console.log(flags.get("cache") ?? false);5console.log(flags.size);Swift1import Foundation2var flags = ["cache": true]3flags["cache"] = nil4print(flags["cache"] ?? false)5print(flags.count)Structs and Independent Copies
A TypeScript interface describes an object shape at compile time; it does not turn an object into a Swift-style value. Object assignment still aliases the JavaScript object. Swift struct declares a value type. Assigning a struct creates an independent value…
TypeScript1export {};2interface Toggle { enabled: boolean }3const first: Toggle = {enabled: false};4const second = first;5second.enabled = !second.enabled;6console.log(first.enabled, second.enabled);Swift1import Foundation2struct Toggle {3 var enabled: Bool4 mutating func flip() { enabled.toggle() }5}
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 lessonsTypeScript Ports
2 lessonsFrequently asked questions
Who is Swift for TypeScript Developers for?
For people who already write TypeScript and want to learn Swift. Each lesson starts from TypeScript 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 TypeScript basics: variables, conditions, loops, functions and collections.
How many lessons does Swift for TypeScript Developers have?
Swift for TypeScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Swift for TypeScript Developers cover?
The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.
Is Swift for TypeScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.