View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Go small with Embedded Swift

    Embedded Swift brings the safety and expressivity of Swift to constrained environments. Explore how Embedded Swift runs on a variety of microcontrollers through a demonstration using an off-the-shelf Matter device. Learn how the Embedded Swift subset packs the benefits of Swift into a tiny footprint with no runtime, and discover plenty of resources to start your own Embedded Swift adventure.

    Capítulos

    • 0:00 - Introduction
    • 0:25 - Agenda
    • 0:46 - Why Embedded Swift
    • 2:30 - Showcase
    • 2:47 - The plan
    • 3:39 - Getting started
    • 6:19 - Using Swift's interoperability to control the LED
    • 7:12 - Using an ergonomic LED struct
    • 10:07 - Adding the Matter protocol
    • 13:43 - Using a Swift enum in the event handler
    • 16:52 - Demo summary
    • 17:34 - How Embedded Swift differs
    • 19:48 - Explore more
    • 21:32 - Wrap up

    Recursos

    • Tools used: Neovim
    • Swift MMIO
    • Swift Forums Embedded Discussion
    • Swift Embedded Example Projects
    • Embedded Swift User Manual
    • A Vision for Embedded Swift
    • Swift Matter Examples
    • Forum: Programming Languages
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC21

    • Add support for Matter in your smart home app
  • Buscar neste vídeo...
    • 3:50 - Empty Embedded Swift application

      @_cdecl("app_main")
      func app_main() {
        print("🏎️   Hello, Embedded Swift!")
      }
    • 6:48 - Turning on LED to blue color

      @_cdecl("app_main")
      func app_main() {
        print("🏎️   Hello, Embedded Swift!")
        var config = led_driver_get_config()
        let handle = led_driver_init(&config)
        led_driver_set_hue(handle, 240) // blue
        led_driver_set_saturation(handle, 100) // 100%
        led_driver_set_brightness(handle, 80) // 80%
        led_driver_set_power(handle, true)  
      }
    • 8:32 - Using an LED object

      let led = LED()
      
      @_cdecl("app_main")
      func app_main() {
        print("🏎️   Hello, Embedded Swift!")
      
        led.color = .red
        led.brightness = 80
      
        while true {
          sleep(1)
          led.enabled = !led.enabled
          if led.enabled {
            led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
          }
        }
      }
    • 12:44 - Matter application controlling an LED light

      let led = LED()
      
      @_cdecl("app_main")
      func app_main() {
        print("🏎️   Hello, Embedded Swift!")
        
        // (1) create a Matter root node
        let rootNode = Matter.Node()
        rootNode.identifyHandler = {
          print("identify")
        }
        
        // (2) create a "light" endpoint, configure it
        let lightEndpoint = Matter.ExtendedColorLight(node: rootNode)
        lightEndpoint.configuration = .default
        lightEndpoint.eventHandler = { event in
          print("lightEndpoint.eventHandler:")
          print(event.attribute)
          print(event.value)
      
          switch event.attribute {
          case .onOff:
            led.enabled = (event.value == 1)
          
          case .levelControl:
            led.brightness = Int(Float(event.value) / 255.0 * 100.0)
          
          case .colorControl(.currentHue):
            let newHue = Int(Float(event.value) / 255.0 * 360.0)
            led.color = .hueSaturation(newHue, led.color.saturation)
          
          case .colorControl(.currentSaturation):
            let newSaturation = Int(Float(event.value) / 255.0 * 100.0)
            led.color = .hueSaturation(led.color.hue, newSaturation)
          
          case .colorControl(.colorTemperatureMireds):
            let kelvins = 1_000_000 / event.value
            led.color = .temperature(kelvins)
          
          default:
            break
          }
        }
        
        // (3) add the endpoint to the node
        rootNode.addEndpoint(lightEndpoint)
        
        // (4) provide the node to a Matter application, start the application
        let app = Matter.Application()
        app.eventHandler = { event in
          print(event.type)
        }
        app.rootNode = rootNode
        app.start()
        
      }
    • 18:03 - Reflection example

      // Reflection needs metadata records
      
      let mirror = Mirror(reflecting: s)
      mirror.children.forEach { … }
      
      struct MyStruct {
        var count: Int
        var name: String
      }
    • 18:57 - Unavailable features will produce errors

      // Unavailable features will produce errors
      
      protocol Countable {
        var count: Int { get }
      }
      
      func count(countable: any Countable) {
        print(countable.count)
      }
    • 19:24 - Prefer generics over “any” types

      // Prefer generics over “any” types
      
      protocol Countable {
        var count: Int { get }
      }
      
      func count(countable: some Countable) {
        print(countable.count)
      }

Developer Footer

  • Vídeos
  • WWDC24
  • Go small with Embedded Swift
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines