我正在尝试创建一个具有 Hashable 项和 Any 项的元组类型,并在 Dictionary 的自定义初始化程序中使用它。然而,斯威夫特不会以这种方式使用 Hashable,我被困在另一种选择中。我不想将我可以创建的字典限制为仅使用字符串作为键。
protocol CollectionInitializeable {
associatedtype T
init(items: [T])
}
extension Dictionary: CollectionInitializeable {
typealias T = (Hashable, Any) // not allowed
init(items: [T]) {
self.init()
// etc...
}
}