Swift for Dart Developers
Move from Dart to Swift through value and reference semantics, optionals, Unicode, protocols, and ARC. Complete 48 multi-file exercises, build a parcel desk, and port two complete Dart programs.
Dart and Swift side by side
The same program in Dart and in Swift, from the lessons of this course.
Bindings and Mutation
A Dart final variable is assigned once, but the object it names can still change. A const list is a compile-time constant and cannot be mutated. Swift let also fixes a binding, but a Swift array is a value: changing its elements requires var. Here a Dart…
Dart1void main() {2 final route = ['east'];3 final alias = route;4 alias.clear();5 print(route.length);6}Swift1import Foundation2let route = ["east"]3var copy = route4copy.removeAll()5print(route.count, copy.count)Strings and Interpolation
Dart interpolates with $name or ${expression}. Swift uses a backslash followed by parentheses around the expression. Both can concatenate strings, but neither interpolation syntax can be copied unchanged into the other language. Swift String is a value type…
Dart1void main() {2 final retries = 2;3 print('attempts=${retries + 1}; ready=${retries < 4}');4}Swift1import Foundation2let retries = 23print("attempts=\(retries + 1); ready=\(retries < 4)")Switch and Patterns
Dart switch expressions and Swift switches can both express a finite decision. Swift statement cases do not implicitly fall through, and every possible input must be handled. A default catches values not handled by earlier patterns. Several literal patterns…
Dart1void main() {2 final command = 'pause';3 final action = switch (command) {4 'stop' || 'pause' => 'hold',5 'play' => 'start',6 _ => 'ignore',7 };8 print(action);9}Swift1import Foundation2let command = "pause"3switch command {4case "stop", "pause": print("hold")5case "play": print("start")6default: print("ignore")7}Functions and Labels
Dart named parameters are declared inside braces and may be optional with defaults or marked required. Swift argument labels are separate from parameter names: to person exposes to at the call while the function uses person. A default value lets callers omit…
Dart1String announce(String person, {String tone = 'hello'}) {2 return '$tone $person';3}Swift1import Foundation2func announce(to person: String, tone: String = "hello") -> String {3 return tone + " " + person4}Dictionaries and Missing Keys
A Dart Map lookup returns a nullable value when a key may be absent. Swift Dictionary subscripting similarly returns an optional. Both distinguish a key's presence from a stored numeric zero. Swift dictionaries have value semantics, unlike Dart maps whose…
Dart1void main() {2 final cache = {'draft': 6, 'live': 0};3 print(cache.remove('draft'));4 print(cache['draft'] ?? -1);5 print(cache['live'] ?? -1);6}Swift1import Foundation2var cache = ["draft": 6, "live": 0]3print(cache.removeValue(forKey: "draft") ?? -1)4print(cache["draft"] ?? -1)5print(cache["live"] ?? -1)Structs and Independent Copies
Dart user-defined class instances have reference semantics, including classes used to represent data. Assigning one to a second variable does not make a new instance. Swift offers struct for value semantics: assigning a struct copies its value. A method that…
Dart1class Position {2 int x;3 int y;4 Position(this.x, this.y);5 Position copy() => Position(x, y);6 void reflect() { x = -x; }7}Swift1import Foundation2struct Position {3 var x: Int4 var y: Int5 mutating func reflect() { x = -x }6}
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 lessonsDart Ports
2 lessonsFrequently asked questions
Who is Swift for Dart Developers for?
For people who already write Dart and want to learn Swift. Each lesson starts from Dart 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 Dart basics: variables, conditions, loops, functions and collections.
How many lessons does Swift for Dart Developers have?
Swift for Dart Developers contains 48 interactive lessons you can complete at your own pace.
What does Swift for Dart Developers cover?
The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.
Is Swift for Dart Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.