Menu
CoddyTech
Course

Swift for PHP Developers

Move from PHP 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 PHP programs.

PHP and Swift side by side

The same program in PHP and in Swift, from the lessons of this course.

  1. Bindings and Mutation

    Ordinary PHP variables can hold values of different types over time. Reassigning label from text to an integer does not change saved. PHP parameter and property declarations can impose separate type constraints, and strict_types affects scalar call coercions…

    PHP
    1<?php2declare(strict_types=1);3$label = "draft";4$saved = $label;5$label = 17;6echo "$saved $label\n";
    Swift
    1let saved = "draft"2var label = saved3label = "ready"4print(saved, label)
  2. Strings and Interpolation

    PHP double-quoted strings interpolate variables, and concatenation uses a dot. Complex expressions are often formatted or combined explicitly, as the arithmetic output here shows. PHP strings are byte sequences; str_starts_with checks the supplied prefix…

    PHP
    1<?php2declare(strict_types=1);3$done = 3;4echo "progress=", $done * 25, "%\n";5echo str_starts_with("report.csv", "report") ? "true\n" : "false\n";
    Swift
    1let done = 32print("progress=\(done * 25)%")3print("report.csv".hasPrefix("report"))
  3. Switch and Patterns

    PHP match is an expression that uses strict comparisons and returns a selected value. Multiple conditions can share an arm, and an unhandled value raises UnhandledMatchError if there is no default. It differs from PHP switch, whose comparison and fallthrough…

    PHP
    1<?php2declare(strict_types=1);3$command = "pause";4echo match ($command) {5    "pause", "stop" => "idle",6    default => "running"7}, "\n";
    Swift
    1let command = "pause"2switch command {3case "pause", "stop": print("idle")4default: print("running")5}
  4. Functions and Labels

    PHP supports named arguments using the declared parameter names, so changing a public parameter name can affect callers. Positional arguments may precede named ones. A Swift external label has a similar readability role but can differ from the local parameter…

    PHP
    1<?php2declare(strict_types=1);3function echo_sound(string $sound, int $times): string {4    return str_repeat($sound, $times);5}6echo echo_sound("ha", times: 3), "\n";
    Swift
    1func echo(_ sound: String, times count: Int) -> String {2    return String(repeating: sound, count: count)3}
  5. Dictionaries and Missing Keys

    PHP arrays are ordered maps. unset removes a key, while assigning null keeps an entry that array_key_exists can still find. The ?? fallback treats both a missing key and a null value as absent for that expression. Count includes present null entries, so…

    PHP
    1<?php2declare(strict_types=1);3$settings = ["font" => 14, "gap" => 2];4unset($settings["gap"]);5echo $settings["gap"] ?? 8, "\n";6echo count($settings), "\n";
    Swift
    1var settings = ["font": 14, "gap": 2]2settings["gap"] = nil3print(settings["gap"] ?? 8)4print(settings.count)
  6. Structs and Independent Copies

    PHP object assignment copies the object identifier, so first and second refer to the same Heading instance. This differs from ordinary array assignment. clone creates a separate object but is shallow unless the class customizes its cloning behavior for…

    PHP
    1<?php2declare(strict_types=1);3class Heading {4    public function __construct(public string $direction) {}5}6$first = new Heading("north");7$second = $first;8$second->direction = "west";9echo "$first->direction $second->direction\n";
    Swift
    1struct Heading {2    var direction: String3    mutating func turnWest() { direction = "west" }4}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for PHP developers

Learn Swift from another language

Frequently asked questions

Who is Swift for PHP Developers for?

For people who already write PHP and want to learn Swift. Each lesson starts from PHP 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 PHP basics: variables, conditions, loops, functions and collections.

How many lessons does Swift for PHP Developers have?

Swift for PHP Developers contains 48 interactive lessons you can complete at your own pace.

What does Swift for PHP Developers cover?

The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.

Is Swift for PHP Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Swift for PHP Developers for free

Get started