@@ -87,17 +87,19 @@ Selected values must conform to `Equatable` for change detection. Add `Equatable
8787
8888### Updating State
8989
90- Use the projected value (` $ ` ) to access setter methods :
90+ The projected value (` $ ` ) returns a standard SwiftUI ` Binding<Value> ` :
9191
9292``` swift
93- // Set value directly
94- $counter.set (10 )
93+ // Use with any SwiftUI control that accepts Binding
94+ Stepper (value : $counter) { Text (" Count: \( Int (counter)) " ) }
95+ Slider (value : $counter, in : 0 ... 100 )
96+ Toggle (" Enabled" , isOn : $isEnabled)
9597
96- // Set with closure (receives current value )
98+ // Set with closure (Brownie extension on Binding )
9799$counter.set { $0 + 1 }
98100
99- // For nested types, replace the whole object
100- $user.set ( User ( name : " John " ) )
101+ // Access nested properties via Binding subscript
102+ TextField ( " Name " , text : $user.name )
101103```
102104
103105### Multiple Selectors
@@ -124,18 +126,26 @@ struct MyView: View {
124126
125127### TextField Binding
126128
127- For two-way binding with TextField, create a ` Binding ` :
129+ Use the binding directly or select a nested property :
128130
129131``` swift
132+ // Option 1: Select the nested property directly
133+ struct UserView : View {
134+ @UseStore (\BrownfieldStore.user .name ) var name
135+
136+ var body: some View {
137+ TextField (" Name" , text : $name)
138+ .textFieldStyle (.roundedBorder )
139+ }
140+ }
141+
142+ // Option 2: Select parent and access nested binding
130143struct UserView : View {
131144 @UseStore (\BrownfieldStore.user ) var user
132145
133146 var body: some View {
134- TextField (" Name" , text : Binding (
135- get : { user.name },
136- set : { $user.set (User (name : $0 )) }
137- ))
138- .textFieldStyle (.roundedBorder )
147+ TextField (" Name" , text : $user.name )
148+ .textFieldStyle (.roundedBorder )
139149 }
140150}
141151```
@@ -245,19 +255,18 @@ Property wrapper for SwiftUI with required KeyPath selector:
245255@UseStore (\BrownfieldStore.counter ) var counter
246256```
247257
248- | Property | Type | Description |
249- | ---------------- | -------------- | ---------------------------- |
250- | ` wrappedValue ` | ` Value ` | Selected value (read-only) |
251- | ` projectedValue ` | ` StoreBinding ` | Setter access via ` $counter ` |
258+ | Property | Type | Description |
259+ | ---------------- | ---------------- | ------- ---------------------------- |
260+ | ` wrappedValue ` | ` Value ` | Selected value (read-only) |
261+ | ` projectedValue ` | ` Binding<Value> ` | Standard SwiftUI binding via ` $var ` |
252262
253- ### StoreBinding
263+ ### Binding Extension
254264
255- Provides setter methods via projected value ( ` $counter ` ) :
265+ Brownie adds a ` set ` method to ` Binding ` for closure-based updates :
256266
257- | Method | Description |
258- | --------- | ---------------------------------------------- |
259- | ` set(_:) ` | Set value directly |
260- | ` set(_:) ` | Set value with closure receiving current value |
267+ ``` swift
268+ $counter.set { $0 + 1 } // increment using current value
269+ ```
261270
262271### Store< ; State> ;
263272
0 commit comments