Quiero crear un tipo genérico, que acepta todo lo que se ajusta a CustomStringConvertible
y luego itera a través de los elementos.
Aquí está un ejemplo que destila por ese problema:
public struct Test<ItemType: CustomStringConvertible, Hashable>: View {
var items: [ItemType]
public var body: some View {
ForEach(items, id: \.self) { item in
Text("test")
}
}
}
let items: [String] = ["a", "b"]
let viewController = UIHostingController(rootView: Test(items: items))
Así que me da un error
Generic struct 'ForEach' requires that 'ItemType' conform to 'Hashable'
y
Generic parameter 'Hashable' could not be inferred
Entonces, ¿qué estoy haciendo mal?