示例工程 39-focus-keyboard-commands

39-focus-keyboard-commands/Diagnostics/KeyPressReturnsBool.swift

swift · 0.3 KB

// 故意编译失败:onKeyPress 的闭包要返回 KeyPress.Result,不是 Bool。
// 复现:swiftc -typecheck Diagnostics/KeyPressReturnsBool.swift
import SwiftUI
 
struct Bad: View {
    var body: some View {
        Text("x").onKeyPress(.return) {
            true
        }
    }
}