Swapping two variables in Swift using Functions
func swap(a: Int ,b: Int) -> (Int,Int){ return (b,a) } var a: Int = 10 , b: Int = 20 print("Before swapping", a, b) var s = swap(a,b:b) print("After swapping ", s.0, s.1 )
Before swapping 10 20 After swapping 20 10
Here we have swapped the two numbers by using Functions.
Comments :