我有一个接受通用集合的函数。
func foo<T: BidirectionalCollection>(_ bar: T)
where T.Iterator.Element == UInt8,
T.SubSequence: BidirectionalCollection & RangeReplaceableCollection,
T.SubSequence.Iterator.Element == UInt8,
T.SubSequence.Index == T.Index,
T.SubSequence.SubSequence == T.SubSequence
{
//
}
我想将此函数称为Data
作为T:
foo(Data())
但是,这会产生错误:
错误:通用参数&#39; T&#39;无法推断
这里发生了什么?如何使用Data
实例正确调用函数?
答案 0 :(得分:1)
我认为问题是Data.SubSequence
不符合RangeReplaceableCollection
协议,而您的通用函数有此要求:
T.SubSequence: BidirectionalCollection & RangeReplaceableCollection