|
Within a Form I have a "Your Current Department" Picker for the app user to select their department of employment (Sales, Management, etc.). This Picker's selection pulls from the viewModel. Here is a link to the code on GitHub. The following two errors on the ProfileFormView inhibit compilation:
The "Department" is a variable within the Employee model:
If I add Hashable to this struct, I get the following two errors:
|
|
Try to add those methods in your struct like so
and add protocols to your struct Employee accordingly.
|
|
@ygeras Thank you! Your suggestions removed the errors in my model, but I still have the two errors in the ProfileFormView: "Generic struct 'Picker' requires that 'Department' conform to 'Hashable'" "Referencing initializer 'init(_:selection:content:)' on 'Picker' requires that 'Department' conform to 'Hashable'" |
|
As per Hashable protocol you have to do as follows:
You Department type is enum. But the point is that it is a mixture of associated values and cases without them. On the other hand I found such solution workable
So theoretically this might sovle your problem ->
At least in playgrounds it generates hashValue accordingly. |
SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.