Last active
August 29, 2015 14:04
-
-
Save memfrag/eb6a8c88e1d602016cfc to your computer and use it in GitHub Desktop.
[Swift] Swap Operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operator infix <=> {} | |
infix func <=> <T>(inout left: T, inout right: T) { | |
let tmp = left | |
left = right | |
right = tmp | |
} | |
var a = 1337 | |
var b = 4711 | |
a <=> b | |
// a is now 4711 and b is 1337 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment