summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorven <vendethiel@hotmail.fr>2015-10-08 22:49:11 +0200
committerven <vendethiel@hotmail.fr>2015-10-08 22:49:11 +0200
commit005c2d3bb268b6046aaa0151236ead2841a839d7 (patch)
treeae5d1eb789e003cafa8bfab904d7402fbdb3a2d1
parent6d85694f3b52f5f9ff0205488067f1224608e19b (diff)
parent707c8db171cb5239682332f14fd2098901741c63 (diff)
Merge pull request #1397 from silvansky/master
[swift/en] Add generics operator in Swift
-rw-r--r--swift.html.markdown14
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"
```