示例工程 34-drawing-shapes-canvas
34-drawing-shapes-canvas/Diagnostics/ShadingNotColor.swift
// 故意编译失败:`fill` 要的是 GraphicsContext.Shading,不能直接传 Color。
// 复现:swiftc -typecheck Diagnostics/ShadingNotColor.swift
import SwiftUI
struct Bad: View {
var body: some View {
Canvas { context, size in
let rect = CGRect(origin: .zero, size: size)
context.fill(Path(rect), with: .red)
}
}
}