Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add item in collection property wrapper support #521

Open
Sammcb opened this issue Oct 1, 2022 · 1 comment
Open

Add item in collection property wrapper support #521

Sammcb opened this issue Oct 1, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Sammcb
Copy link

Sammcb commented Oct 1, 2022

Describe the bug
In SwiftUI 3, support was added for using a binding of an element in a collection.

struct ExampleView: View {
  @State var directions: [Direction] = [SomeIdentifiableStructWithFields()]

  var body: some View {
    List($directions) { $direction in
      TextField("Instructions", text: $direction.text)
      Text(direction.text)
    }
  }
}

This allows for using a binding to a value and reading the value. Currently this behavior is not supported in Tokamak. In the example above, I get an error on $direction in saying

Cannot use property wrapper projection parameter

This isn't a big issue since you can technically use a ForEach on the count and index into the collection, but would be a nice to have!

Expected behavior
Using a binding would work in the above code snippet.

Desktop (please complete the following information):

  • OS: macOS 12.6
  • Browser: Safari
  • Version of the browser: 16
  • Version of Tokamak: 0.11.0

Thanks!

@Sammcb Sammcb added the bug Something isn't working label Oct 1, 2022
@davdroman
Copy link

davdroman commented Nov 27, 2022

The reason is that State must declare init(projectedValue: Binding<Value>).

Property wrappers can enable passing a projected-value argument to a property-wrapped parameter by declaring var projectedValue, and implementing an init(projectedValue:) that meets the following requirements: [...]

Source: https://github.com/apple/swift-evolution/blob/main/proposals/0293-extend-property-wrappers-to-function-and-closure-parameters.md#passing-a-projected-value-argument

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants