【发布时间】:2019-08-12 21:29:36
【问题描述】:
protocol Component {}
struct Container {
let map: [Component: Component]
}
在上面的代码中,如何指定map 的键可以包含任何类型的Components 也是Hashable?
【问题讨论】:
protocol Component {}
struct Container {
let map: [Component: Component]
}
在上面的代码中,如何指定map 的键可以包含任何类型的Components 也是Hashable?
【问题讨论】:
试试代码
protocol Component {}
struct Container<T: Hashable & Component> {
let map: [T: Component]
}
或者
protocol Component {}
struct Container<T> where T: Hashable, T: Component {
let map: [T: Component]
}
【讨论】: