Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created March 26, 2015 23:26
Show Gist options
  • Save JadenGeller/8afdbaa6cf8bf30bf645 to your computer and use it in GitHub Desktop.
Save JadenGeller/8afdbaa6cf8bf30bf645 to your computer and use it in GitHub Desktop.
Swift Logical XOR
infix operator ^^ { associativity left precedence 120 }
func ^^<T : BooleanType, U : BooleanType>(lhs: T, rhs: U) -> Bool {
return lhs.boolValue != rhs.boolValue
}
// Example
false ^^ false // -> false
false ^^ true // -> true
true ^^ false // -> true
true ^^ true // -> false
@AmitaiB
Copy link

AmitaiB commented Nov 17, 2016

//Swift 3
precedencegroup BooleanPrecedence { associativity: left }
infix operator ^^ : BooleanPrecedence
/**
Swift Logical XOR operator

true  ^^ true   // false
true  ^^ false  // true
false ^^ true   // true
false ^^ false  // false
  • parameter lhs: First value.
  • parameter rhs: Second value.
    */
    func ^^(lhs: Bool, rhs: Bool) -> Bool {
    return lhs != rhs
    }

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