Created
June 8, 2017 20:27
-
-
Save thomas-alrek/fb28ab0cb7172de72194596e873e2edd to your computer and use it in GitHub Desktop.
Increment_Decrement_Operators.swift
This file contains hidden or 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
| prefix operator ++ | |
| prefix operator -- | |
| postfix operator ++ | |
| postfix operator -- | |
| @discardableResult prefix func ++( a: inout Int) -> Int { | |
| a += 1 | |
| return a | |
| } | |
| @discardableResult prefix func --( a: inout Int) -> Int { | |
| a -= 1 | |
| return a | |
| } | |
| @discardableResult postfix func ++( a: inout Int) -> Int { | |
| defer { a += 1 } | |
| return a | |
| } | |
| @discardableResult postfix func --( a: inout Int) -> Int { | |
| defer { a -= 1 } | |
| return a | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment