In Swift 2, I was able to write a function that worked in any order, for example (String, Int). It looked something like this:
func test<T: SequenceType where T.Generator.Element == (String, Int)>(input: T) {
for (k, v) in input {
print(k, "=", String(v))
}
}
Using a tuple as a limited type was especially useful so that it could accept dictionaries, such as [String:Int]since their sequence type consisted of tuples.
In Swift 3, I believe that a similar function would be:
func test<T: Sequence>(input: T) where T.Iterator.Element == (String, Int) {
for (k, v) in input {
print(k, "=", String(v))
}
}
But an attempt to pass in [String:Int], for example:, test(input: ["a": 1, "b": 2])causes an error:
General parameter 'T' cannot be displayed
, Swift 3 (Key, Value) , , . , , where T.Iterator.Element == String, - [String] .
-, , Swift 3?