Menu
CoddyTech
Course

Swift for C# Developers

Bring C# experience to Swift value semantics, optionals, Unicode, protocols and ARC. Complete 48 multi-file tasks, a four-step parcel desk project and two complete C# program ports.

C# and Swift side by side

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

  1. Bindings and Mutation

    C# var asks the compiler to infer a type; the local still permits reassignment. Swift separates that choice into let for a binding that cannot be reassigned and var for one that can. Both languages keep the inferred type fixed. A C# const requires a…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program6{7    static void Main()8    {9        var mode = "draft";10        mode = "ready";11        Console.WriteLine(mode);12    }13}
    Swift
    1var mode = "draft"2mode = "ready"3let label = mode4print(label)
  2. Strings and Interpolation

    C# interpolated strings begin with $ and insert expressions inside braces. Swift inserts an expression with \(...) inside an ordinary string literal. A Swift String is a value type, while C# string is an immutable reference type; replacing a variable does not…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program6{7    static void Main()8    {9        int side = 4;10        Console.WriteLine($"{side} squared = {side * side}");11    }12}
    Swift
    1let side = 42print("\(side) squared = \(side * side)")
  3. Switch and Patterns

    C# switch statements traditionally use break to finish a case and forbid ordinary fall-through between nonempty case bodies. Swift finishes a case automatically. Its switch must cover every possible input, often with default; explicit fallthrough exists but…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program6{7    static void Main()8    {9        string command = "w";10        switch (command) { case "w": case "save": Console.WriteLine("write"); break; default: Console.WriteLine("ignore"); break; }11    }12}
    Swift
    1let command = "w"2switch command {3case "w", "save": print("write")4default: print("ignore")5}
  4. Functions and Labels

    C# callers may use named arguments, but most ordinary calls can omit those names. Swift external argument labels are part of the calling convention and usually must appear. An underscore suppresses an external label while retaining a useful parameter name…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4static class TextTools { public static string Repeat(string text, int times) { return string.Join("/", Enumerable.Repeat(text, times)); } }5
    6class Program7{8    static void Main()9    {10        Console.WriteLine(TextTools.Repeat("ha", times: 3));11    }12}
    Swift
    1func repeatText(_ text: String, times: Int) -> String {2    return Array(repeating: text, count: times).joined(separator: "/")3}
  5. Dictionaries and Missing Keys

    C# dictionary indexer reads throw when a key is absent. TryGetValue exposes absence through its Boolean result and an output parameter. Swift dictionary lookup returns an optional value; writing nil through the subscript removes the key. A defaulted Swift…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program6{7    static void Main()8    {9        var settings = new Dictionary<string, int> { { "zoom", 125 } };10        settings.Remove("zoom");11        int zoom;12        Console.WriteLine(settings.TryGetValue("zoom", out zoom) ? zoom : 100);13    }14}
    Swift
    1var settings = ["zoom": 125]2settings["zoom"] = nil3print(settings["zoom"] ?? 100)
  6. Structs and Independent Copies

    C# structs and Swift structs are value types. Assignment copies the value, but reference-valued fields can still refer to shared objects. Neither language promises a recursive deep copy. In this example, changing a copied label affects only that struct, while…

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4class Cell { public string Text; }5struct LabelledBox { public string Label; public Cell Shared; }6
    7class Program8{9    static void Main()10    {11        var original = new LabelledBox { Label = "old", Shared = new Cell { Text = "one" } };12        var copy = original;13        copy.Label = "new";14        copy.Shared.Text = "two";15        Console.WriteLine(original.Label + " " + original.Shared.Text);16    }17}
    Swift
    1final class Cell { var text: String; init(text: String) { self.text = text } }

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for C# developers

Learn Swift from another language

Frequently asked questions

Who is Swift for C# Developers for?

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

How many lessons does Swift for C# Developers have?

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

What does Swift for C# Developers cover?

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

Is Swift for C# 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 C# Developers for free

Get started