Video summary

WWDC24: Go small with Embedded Swift | Apple

Main summary

Key takeaways

Technology

High-level concept

Embedded Swift is a new compilation mode — a strict subset of Swift — designed for constrained embedded devices (microcontrollers, kernel-level and other low-level code). It brings Swift ergonomics and safety to embedded development while producing small, simple binaries. Embedded Swift is currently experimental/preview and not source-stable; it is intended to be used with preview/nightly toolchains from swift.org.

Status: experimental/preview (use preview/nightly Swift toolchains from swift.org)

Why use Embedded Swift

  • Enables Swift on microcontrollers and other low-level contexts (Apple already uses it in the Secure Enclave Processor).
  • Key benefits:
    • Memory safety
    • Readable, ergonomic APIs
    • Closures for callbacks
    • Powerful enums and pattern matching
    • Full generics (specialized at compile time)
    • Easy interop with existing C and C++ SDKs

Demo (practical walkthrough)

Target and goal

  • Hardware: ESP32C6 dev board (RISC‑V MCU) with RGB LED.
  • Development: Mac over USB, then battery-powered for wireless operation.
  • Goal: build a HomeKit-enabled color LED light using Matter (open smart-home standard).

Build and integration approach

  • Use the vendor-provided SDK (C/C++) unchanged by importing it via a bridging header.
  • Build tooling: CMake plus vendor boilerplate files (YAML, CSV, sdkconfig) and a vendor Python script to build, flash, and monitor firmware.
  • Editor: Neovim + LSP for autocompletion, docs, and inline errors.

Implementation highlights

  • Call C APIs directly from Swift for low-level control, then wrap them in ergonomic Swift types (for example, an LED object with properties like enabled and brightness) so app logic remains clear and safe.
  • Use closures for event callbacks instead of unsafe function pointers.
  • Use Swift enums with associated values and pattern matching to model Matter attributes (on/off, level control, color control with hue/saturation or temperature).
  • Flash the device, commission it with Matter, and control the light from the Home app. Wireless control is verified on battery power.

Language subset: what’s allowed and what’s not

Supported features

  • Most common Swift language features are available: value and reference types, closures, optionals, error handling, generics, enums, pattern matching, and more.

Disallowed or omitted features (to reduce code size and runtime metadata)

  • Runtime reflection (Mirror APIs) — heavy metadata cost
  • Metatypes and “any” existential types
  • Other features that require runtime type metadata

Workarounds and recommendations

  • Prefer compile-time generics (including some/opaque types) and compile-time specialization to avoid runtime metadata needs.

Tooling, resources, and ecosystem

Recommended reading and resources

  • Embedded Swift — User Manual (how to get started, compiler flags, vendor build-system integration)
  • Swift Evolution — Embedded Swift vision document (design and requirements)
  • Example projects on GitHub (ARM and RISC‑V boards, Playdate, different build systems and integration patterns)
  • Swift MMIO library — safe, ergonomic APIs for memory-mapped I/O (hardware register access)
  • Swift forums — new “Embedded” subcategory for discussion, experiments, and questions
  • WWDC 2021 session on Matter (for deeper Matter protocol background)

Supported backends (preview)

  • ARM and RISC‑V, 32-bit and 64-bit variants. Adding support for more ISAs is straightforward.

Practical guidance / takeaways

  • Embedded Swift is well suited to hobbyists and embedded developers who want Swift’s safety and clarity while interoperating with existing C/C++ SDKs.
  • Start from vendor SDK examples, use bridging headers, and wrap C APIs into Swift layers.
  • Prefer generics and other compile-time techniques to avoid disallowed runtime features.
  • Use swift.org preview toolchains and example repositories as templates, and post feedback/questions to the Swift forums.

Main speaker / source

  • Kuba Mracek (Apple)

Rate this summary

Your feedback will help improve summaries.

Improve this summary

Reprocess with a stronger model when the summary feels incomplete or inaccurate.

Pro

Translate summary in another language

Pro

Ask questions to this video

Chat for follow-up questions, clarifications, and source-backed answers.

Coming soon

Share this summary

Original video