diff options
author | Valentine Silvansky <v.silvansky@gmail.com> | 2015-10-08 10:00:13 +0300 |
---|---|---|
committer | Valentine Silvansky <v.silvansky@gmail.com> | 2015-10-08 10:00:13 +0300 |
commit | 707c8db171cb5239682332f14fd2098901741c63 (patch) | |
tree | a72c250a1373fb828fbd561762e7487ceadc0e13 /swift.html.markdown | |
parent | abd7444f9e5343f597b561a69297122142881fc8 (diff) |
Add generics operator in Swift
Diffstat (limited to 'swift.html.markdown')
-rw-r--r-- | swift.html.markdown | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/swift.html.markdown b/swift.html.markdown index a40e86c8..75535e43 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -574,4 +574,18 @@ print(mySquare.sideLength) // 4 // change side length using custom !!! operator, increases size by 3 !!!mySquare print(mySquare.sideLength) // 12 + +// Operators can also be generics +infix operator <-> {} +func <-><T: Equatable> (inout a: T, inout b: T) { + let c = a + a = b + b = c +} + +var foo: Float = 10 +var bar: Float = 20 + +foo <-> bar +print("foo is \(foo), bar is \(bar)") // "foo is 20.0, bar is 10.0" ``` |