스트리밍은 대부분의 브라우저와
Developer 앱에서 사용할 수 있습니다.
-
Embedded Swift로 경량화하기
Embedded Swift를 사용하면 제한된 환경에도 Swift의 안전성과 표현성을 그대로 누릴 수 있습니다. 규격화된 Matter 기기를 사용한 데모를 통해 Embedded Swift에서 다양한 마이크로컨트롤러를 실행하는 방법을 확인해 보세요. Embedded Swift 하위 집합이 그토록 작은 공간에 런타임 없이 Swift의 이점을 모두 담을 수 있었던 방법과 Embedded Swift 개발의 첫걸음을 돕는 수많은 리소스를 살펴볼 수 있습니다.
챕터
- 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
리소스
- A Vision for Embedded Swift
- Embedded Swift User Manual
- Forum: Programming Languages
- Swift Embedded Example Projects
- Swift Forums Embedded Discussion
- Swift Matter Examples
- Swift MMIO
- Tools used: Neovim
관련 비디오
WWDC21
-
다운로드Array
-
-
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) }
-
-
찾고 계신 콘텐츠가 있나요? 위에 주제를 입력하고 원하는 내용을 바로 검색해 보세요.
쿼리를 제출하는 중에 오류가 발생했습니다. 인터넷 연결을 확인하고 다시 시도해 주세요.