Skip to content

Instantly share code, notes, and snippets.

@aciidgh
Created December 14, 2015 19:37
Show Gist options
  • Save aciidgh/503f633a13176546239e to your computer and use it in GitHub Desktop.
Save aciidgh/503f633a13176546239e to your computer and use it in GitHub Desktop.
Swift ++ operator
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
}
@milanpanchal
Copy link

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:

var i = 0
print("Value of i : \(i++)")
i++ // **WARNING: Result of operator ++ is unused**
print("Value of i : \(++i)")

P.S.
I don't want to replace i++ with _ = i++ to just ignore waring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment