Created
December 14, 2015 19:37
-
-
Save aciidgh/503f633a13176546239e to your computer and use it in GitHub Desktop.
Swift ++ operator
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 func ++(inout x: Int) -> Int { | |
x = x + 1 | |
return x | |
} | |
postfix func ++(inout x: Int) -> Int { | |
let oldX = x | |
x = x + 1 | |
return oldX | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works like a charm. But just have a problem for postfix operation i.e.
**WARNING: Result of operator ++ is unused.**
Any solution to avoid that warning?Snippet:
P.S.
I don't want to replace
i++
with_ = i++
to just ignore waring.