Swift: Swapping of 2 variables

This entry is part 26 of 41 in the series Swift

Swapping of 2 variables

func swapTwoInts(inout a: Int, inout b: Int) {
    let temp = a
    a = b
    b = temp

var a1 = 10
var a2 = 20
print("a1 \(a1), a2 \(a2)\n")
swapTwoInts(&a1, b: &a2)
print("a1 \(a1), a2 \(a2)")


Series Navigation<< Swift: Adding and inserting items to a list
Swift: Switch and default case >>

Leave a comment

Leave a Reply