Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Last active April 25, 2020 06:12
Show Gist options
  • Save AppleCEO/f0bf7437f78c7e2577500425c4e1c57c to your computer and use it in GitHub Desktop.
Save AppleCEO/f0bf7437f78c7e2577500425c4e1c57c to your computer and use it in GitHub Desktop.
func swapTwoIntsWithInout(a: inout Int, b: inout Int) {
let temporaryA = a
a = b
b = temporaryA
}
var firstNumber = 10
var secondNumber = 30
print("firstNumber : \(firstNumber)") // 10
print("secondNumber : \(secondNumber)") // 30
swapTwoIntsWithInout(a: &firstNumber, b: &secondNumber)
print("firstNumber : \(firstNumber)") // 30
print("secondNumber : \(secondNumber)") // 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment