Skip to content

Instantly share code, notes, and snippets.

@nemesit
Last active December 14, 2015 12:50
Show Gist options
  • Save nemesit/ff6872723b27e373fde5 to your computer and use it in GitHub Desktop.
Save nemesit/ff6872723b27e373fde5 to your computer and use it in GitHub Desktop.
postfix increment/decrement and prefix increment/decrement, for those who will miss them in Swift 3
postfix operator +++ {}
postfix func +++(inout left: Int) -> Int {
defer {left += 1}
return left
}
postfix operator --- {}
postfix func ---(inout left: Int) -> Int {
defer {left -= 1}
return left
}
prefix operator +++ {}
prefix func +++(inout right: Int) -> Int {
right += 1
return right
}
prefix operator --- {}
prefix func ---(inout right: Int) -> Int {
right -= 1
return right
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment