Last active
August 29, 2015 14:03
-
-
Save fuxx/b518b6d9c02bbdc2c38a to your computer and use it in GitHub Desktop.
This file contains 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
import Cocoa | |
// Operator überladen und missbrauchen | |
@infix func &- (left: Int, right: Int) -> Int { | |
var ergebnis = left - right | |
if (ergebnis < 0) { | |
ergebnis = -ergebnis; | |
} | |
return ergebnis | |
} | |
let x = 0 // Ausgangwert | |
var Entfernung: Int = 0 | |
var y: Int = 3 //Entfernungswert 1 | |
var z: Int = -3 //Entfernungswert 2 | |
// Berechnung der Entfernung mit abs | |
Entfernung = abs(x - y) // Ergebnis ist 3 | |
Entfernung = abs(x - z) // Ergebnis ist 3 | |
// Berechnung der Entfernung mit Operator überladen | |
Entfernung = x &- y // Das Ergebnis lautet jetzt 3 | |
Entfernung = x &- z // Das Ergebnis lautet jetzt 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Antwort auf die Frage von Youtube: https://www.youtube.com/watch?v=zXzuu2RtkL0&google_comment_id=z13qxdijmkzfshydx22nvpqrrn21ejwqx04