Etan Etan - 3 years ago 87
Swift Question

Passing Data into function that accepts generic collection

I have a function that accepts generic collections.

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

I want to call this function with
as T:


However, this gives the error:

error: generic parameter 'T' could not be inferred

What's going on here? How to properly call the function with a

Answer Source

I think the problem is that Data.SubSequence does not conform to RangeReplaceableCollection protocol, while your generic function has this requirement:

T.SubSequence: BidirectionalCollection & RangeReplaceableCollection
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download