Menu
CoddyTech
Course

Swift for C Developers

Move from C pointers, structs and status returns to Swift values, optionals, protocols and ARC. Practice with 48 multi-file tasks, build a parcel desk and port two complete C applications.

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 const qualifies an object or the type accessed through a pointer; it does not generally freeze all reachable data. A const pointer and a pointer to const describe different restrictions. Swift let fixes a binding, while var permits the value to change. A…

    C
    1#include <stdio.h>2#include <stdbool.h>3#include <string.h>4
    5int main(void) {6const int saved = 18;7    int current = saved;8    current = 21;9    printf("%d %d\n", saved, current);10    return 0;11}
    Swift
    1import Foundation2let saved = 183var current = saved4current = 215print("\(saved) \(current)")
  2. Strings and Interpolation

    C printf interprets a format string and expects matching argument types; %% writes a literal percent sign. Swift interpolation inserts a typed expression into a String using a backslash and parentheses. The resulting text can be returned or printed…

    C
    1#include <stdio.h>2#include <stdbool.h>3#include <string.h>4
    5int main(void) {6int percent = 40;7    printf("Downloaded %d%%\n", percent);8    return 0;9}
    Swift
    1import Foundation2let percent = 403print("Downloaded \(percent)%")
  3. Switch and Patterns

    C switch operates on an integer expression, including char and enum values, and cases can fall through unless control leaves them. Swift switch can match strings and richer patterns and has no implicit fallthrough. It must cover all possibilities or supply an…

    C
    1#include <stdio.h>2#include <stdbool.h>3#include <string.h>4
    5int main(void) {6char command = '?';7    switch (command) {8        case 'h':9        case '?': puts("show help"); break;10        case 'q': puts("close"); break;11        default: puts("unknown"); break;12    }13    return 0;14}
    Swift
    1import Foundation2let command = "?"3switch command {4case "help", "?": print("show help")5case "quit": print("close")6default: print("unknown")7}
  4. Functions and Labels

    C and Swift both support free functions, though C declarations and definitions are organized through translation units and headers. Swift sibling source files compile into one module, and these exercises place helpers in Functions.swift while main.swift calls…

    C
    1#include <stdio.h>2static void line(char symbol, int count) { for (int i = 0; i < count; ++i) putchar(symbol); putchar('\n'); }3int main(void) { line('*', 3); return 0; }
    Swift
    1import Foundation2func line(_ symbol: String, count: Int = 3) -> String {3    String(repeating: symbol, count: count)4}
  5. Dictionaries and Missing Keys

    Standard C has no built-in dictionary container; this small comparison uses an array of entries and a lookup function with an explicit fallback. Swift Dictionary provides key lookup returning an Optional. A valid zero value must remain distinct from a missing…

    C
    1#include <stdio.h>2#include <string.h>3typedef struct { const char *key; int value; } Entry;4static int lookup(const Entry *entries, int count, const char *key, int fallback) {5    for (int i = 0; i < count; ++i) if (strcmp(entries[i].key, key) == 0) return entries[i].value;6    return fallback;7}8int main(void) {9    Entry settings[] = {{"zoom", 2}};10    settings[0].value = 3;11    printf("%d %d\n", lookup(settings, 1, "zoom", 1), lookup(settings, 1, "speed", 1));12    return 0;13}
    Swift
    1import Foundation2var settings = ["zoom": 2]3settings["zoom"] = 34print("\(settings["zoom"] ?? 1) \(settings["speed"] ?? 1)")
  6. Structs and Independent Copies

    C struct assignment copies member values, unlike assigning a pointer to the same struct. Swift structs also have value semantics and additionally support methods directly on the type. A Swift instance method that changes stored properties declares mutating…

    C
    1#ifndef THEME_H2#define THEME_H3typedef struct { const char *name; } Theme;4static void theme_select(Theme *theme, const char *name) { theme->name = name; }5#endif
    Swift
    1import Foundation2struct Theme {3    var name: String4    mutating func select(_ value: String) { name = value }5}

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