Chci vytvořit obecný typ, který přijímá cokoliv, co splňuje CustomStringConvertible
a pak iteruje přes tyto položky.
Zde je příklad, který padá dolů tento problém:
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))
Tak jsem si chybu
Generic struct 'ForEach' requires that 'ItemType' conform to 'Hashable'
a
Generic parameter 'Hashable' could not be inferred
Takže co dělám špatně?