What is the output?
func swap<T>(
_ a: inout T,
_ b: inout T
) {
let temp = a
a = b
b = temp
}
var x = 5, y = 9
swap(&x, &y)
print(x)
print(y)
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
9 5
Explanation:
Generic functions use type parameters (like
[/spoiler]