I am currently learn the use of generic functions and realized the problem that they solve with some existing examples in the documentation.
So instead I keep repeating functions that perform the same scheme, I can use generic functions that way:
func swapTwoValues<T>(inout a: T, inout b: T) {
let temporaryA = a
a = b
b = temporaryA
}
But if we think a little more we can use the command Any for that:
func swapTwoStrings(inout a: Any, inout b: Any) {
let temporaryA = a
a = b
b = temporaryA
}
So, why use generic functions if we can do the job using Any?
If you're just swapping things, there's probably no need to use generics over Any. If you actually intend to call any methods on the arguments though, you'll need to either cast them to a type that has those methods (verbose, can fail at runtime, slower), or use generic parameters.