I have a problem and don't know how to solve it. I have several enum's that return a string, used every where in the project, on a separate textPhrases file.
I want to use some of them to fill a picker ( segmented ).
I trying to understand how should I use and setup the tag element.
I was thinking to have a static var that return a tuple with [String:Int] [rawCaseValue, index], but get the folowing error - Type '(String, Int)' cannot conform to 'Hashable'; only struct/enum/class types can conform to protocols
Here is a sample of my code. The second picker works perfect, but I want to refactor that to use the enum provided Strings.
// TextPhrases.swift
// Zinnig
import SwiftUI
enum SalutationClient: String, CaseIterable {
case noChoice = "…"
case sir = "Meneer"
case mrs = "Mevrouw"
case miss = "Mejuffrouw"
static let all = SalutationClient.allCases.map { $0.rawValue }
static var allIndexed : [(String, Int)]{
var tupleArray: [(String, Int)] = []
var ind : Int = 0
for salut in SalutationClient.all //allCases.map({ $0.rawValue })
{
tupleArray.append( (salut, ind))
ind += 1
}
return tupleArray
}
}
// PersonContentView.swift
// Zinnig
/// Main Person view
struct PersonContentView: View {
@State private var selectedSalutation = 0
/// next line will be removed and replace by an enum with Strings
@State private var dayPart: [String] = ["…", "ochtend", "middag", "avond", "nacht"]
@State private var selectedDayPart = 0
...
Form {
Picker(selection: $selectedSalutation, label: Text("Aanspreken met;")) {
ForEach ( SalutationClient.allIndexed, id: \.self ) { salutTuple in
Text((salutTuple.0)).tag((salutTuple.1))
}
}.pickerStyle(SegmentedPickerStyle())
Picker(selection: $selectedDayPart, label: Text("Selecteer een dagdeel")) {
ForEach(0 ..< dayPart.count) {
Text(self.dayPart[$0]).tag($0)
}
}.pickerStyle(SegmentedPickerStyle())
}
The error is - Type '(String, Int)' cannot conform to 'Hashable'; only struct/enum/class types can conform to protocols
How should I proceed to get this working?
Thank you