Skip to content

Instantly share code, notes, and snippets.

@ChenCodes
Last active June 1, 2017 18:41
Show Gist options
  • Save ChenCodes/b2c9da4e33452e1031805803a25158ed to your computer and use it in GitHub Desktop.
Save ChenCodes/b2c9da4e33452e1031805803a25158ed to your computer and use it in GitHub Desktop.
Swap Function that swaps the values of two variables of any type
//When it says Any type, this means that we're dealing with generics
func swap<G>(item_1: inout G, item_2: inout G) {
let temp = item_1
item_1 = item_2
item_2 = temp
}
var one = "1"
var two = "2"
print(one, two) //1, 2
swap(&one, &two)
print(one, two) //2, 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment