를 만들고 싶은데 일반적인 유형을 받을 준수하는 아무것도 CustomStringConvertible
고 다음을 반복하며 그 이상의 항목입니다.
여기에는 예를 걸러내는 아래로는 문제점:
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))
그래서 저는 오류
Generic struct 'ForEach' requires that 'ItemType' conform to 'Hashable'
고
Generic parameter 'Hashable' could not be inferred
그래서 무엇이 잘못된 것입니까?