! - this is the logical not operator:
var x = true
x = !x
print(x)
In Swift 3, this operator is defined as a static function Bool
Type:
public struct Bool {
prefix public static func !(a: Bool) -> Bool
}
There is no built-in mutation method that overrides the boolean, but you can implement it using the operator !:
extension Bool {
mutating func negate() {
self = !self
}
}
var x = true
x.negate()
print(x)
, Swift
( sort() vs. sorted() ).
:
Swift
toggle() :
extension Bool {
mutating func toggle() {
self = !self
}
}