From b97a29ca576ec72dd1546f7872eb5bc5edefae91 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Mar 2026 01:17:08 +0000 Subject: [PATCH] Clarify that @Slot is optional and purely for convenience inits Make it clear throughout that generic View properties are automatically slots without any annotation. Rename the section to "@Slot annotation" and lead with an explicit statement that it is not required, only used to opt in to LocalizedStringKey/String/systemImage convenience inits. https://claude.ai/code/session_0146841j3MHfYwLTTA1Mnd6i --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 70ac3a1..e363549 100644 --- a/README.md +++ b/README.md @@ -62,17 +62,19 @@ Add a third slot and you're writing twelve inits. Add a fourth and it's more tha ## The solution -Annotate your component with `@Slots`. Optional generic properties are automatically recognized as slots; use `@Slot` only when you need options like `.text`. The macro generates every init permutation for you — fully type-safe, using constrained extensions with no casts. +Annotate your component with `@Slots`. Every generic `View` property is automatically a slot — no per-property annotation needed. The macro picks them all up and generates a `@ViewBuilder` init parameter for each one. Mark a slot optional with `?` and the omission variants are generated too. + +The `@Slot` annotation is entirely optional. You only need it when you want convenience inits that accept a `String` or system image name rather than a `@ViewBuilder` closure — the same thing SwiftUI does for `Button`'s label. ```swift import Slots @Slots struct Card: View { - @Slot(.text) + @Slot(.text) // optional: adds LocalizedStringKey / String convenience inits var title: Title - var actions: Actions? + var actions: Actions? // optional slot — no annotation needed var body: some View { ... } } @@ -109,9 +111,13 @@ Card { headerView } // custom view, no actions --- -## Slot options +## The `@Slot` annotation + +You don't need `@Slot` to define a slot. Any generic `View` property — required or optional — is a slot automatically, and `@Slots` generates the corresponding `@ViewBuilder` init parameters without it. + +`@Slot` is purely additive: it attaches convenience options to a slot, asking the macro to also generate inits that accept a plain value (a string, a system image name) and construct the view internally. Without any options it has no effect. -The `@Slot` property annotation accepts one or more options: +The available options are: | Option | Effect | |---|---|