Swift for GDScript Developers
Move from GDScript to Swift through static types, value semantics, optionals, Unicode, protocols and ARC. Complete 48 multi-file exercises, build a parcel desk and port two complete GDScript programs.
GDScript and Swift side by side
The same program in GDScript and in Swift, from the lessons of this course.
Bindings and Mutation
An untyped GDScript local initialized with = remains a Variant binding and can later hold a different type. An explicit type or inferred static type using := instead constrains assignment. A saved String value retains its own value when another binding is…
GDScript1extends SceneTree2 3func _init():4 var label = "draft"5 var saved = label6 label = 177 print(saved, " ", label)8 quit()Swift1let saved = "draft"2var label = saved3label = "ready"4print(saved, label)Strings and Interpolation
GDScript percent formatting combines a format string with values, and %% emits a literal percent sign. Swift interpolation uses a backslash followed by a parenthesized expression inside a String. Both construct text, while begins_with and hasPrefix answer a…
GDScript1extends SceneTree2 3func _init():4 var done = 35 print("progress=%d%%" % (done * 25))6 print("report.csv".begins_with("report"))7 quit()Swift1let done = 32print("progress=\(done * 25)%")3print("report.csv".hasPrefix("report"))Switch and Patterns
GDScript match selects a matching pattern and supports several patterns sharing a branch. Swift switch has its own richer pattern syntax and requires exhaustive coverage. An open set such as all strings generally needs a default for values not explicitly…
GDScript1extends SceneTree2 3func _init():4 var command = "pause"5 match command:6 "pause", "stop":7 print("idle")8 _:9 print("running")10 quit()Swift1let command = "pause"2switch command {3case "pause", "stop": print("idle")4default: print("running")5}Functions and Labels
GDScript functions use positional calls and may declare parameter types and defaults. Swift also supports defaults, but external argument labels are part of its callable interface. A separate local parameter name can be used inside the body, as times count…
GDScript1extends SceneTree2func echo(sound: String, count: int) -> String:3 return sound.repeat(count)4 5func _init():6 print(echo("ha", 3))7 quit()Swift1func echo(_ sound: String, times count: Int) -> String {2 return String(repeating: sound, count: count)3}Dictionaries and Missing Keys
GDScript Dictionary is a shared reference container and uses erase to remove an entry. Assigning null stores a null value rather than meaning removal. get can provide a default and has distinguishes an existing key from an absent one even when its value is…
GDScript1extends SceneTree2 3func _init():4 var settings = {"font": 14, "gap": 2}5 settings.erase("gap")6 print(settings.get("gap", 8))7 print(settings.size())8 quit()Swift1var settings = ["font": 14, "gap": 2]2settings["gap"] = nil3print(settings["gap"] ?? 8)4print(settings.count)Structs and Independent Copies
GDScript user-defined classes have reference identity; assigning an instance to another variable shares the same object. Built-in value types do not turn such a class into a Swift struct. Swift struct assignment preserves independent value state for its…
GDScript1extends SceneTree2class Heading:3 var direction: String4 func _init(value: String):5 direction = value6 func turn_west() -> void:7 direction = "west"8 9func _init():10 var first = Heading.new("north")11 var second = first12 second.turn_west()13 print(first.direction, " ", second.direction)14 quit()Swift1struct Heading {2 var direction: String3 mutating func turnWest() { direction = "west" }4}
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 lessonsGDScript Ports
2 lessonsFrequently asked questions
Who is Swift for GDScript Developers for?
For people who already write GDScript and want to learn Swift. Each lesson starts from GDScript 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 GDScript basics: variables, conditions, loops, functions and collections.
How many lessons does Swift for GDScript Developers have?
Swift for GDScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Swift for GDScript Developers cover?
The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.
Is Swift for GDScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.