Posts

Post not yet marked as solved
1 Replies
0 Views
I was able to work around this by making a wrapper struct for the binding that conforms to Hashable if the value is Hashable. Then I am able to do the following in the NavigationLink: NavigationLink(value: HashableBindingWrapper<Event>(binding: $event) { … } // Later in file: .navigationDestination(for: HashableBindingWrapper<Event>.self) { wrapper in EventEditor(event: wrapper.binding) } It's ugly to need to do this instead of it being supported directly, but it seems to work. Thanks to Ben Scheirman for the suggestion. Here's the code for HashableBindingWrapper: struct HashableBindingWrapper<Value> {     let binding: Binding<Value> } extension HashableBindingWrapper: Equatable where Value: Equatable {     static func == (lhs: HashableBindingWrapper<Value>, rhs: HashableBindingWrapper<Value>) -> Bool {         lhs.binding.wrappedValue == rhs.binding.wrappedValue     } } extension HashableBindingWrapper: Hashable where Value: Hashable {     func hash(into hasher: inout Hasher) {         hasher.combine(binding.wrappedValue.hashValue)     } }
Post not yet marked as solved
4 Replies
0 Views
Thanks @jlagrone. Your second approach is what I was thinking of doing. Was hoping there was some sample code or hints from someone who was familiar with it. But I guess we'll just experiment and figure it out.