To experiment with keeping my app "explanation mark free" I've created my own analogues for !=
and !
operators some time ago (don't want to go into further details on this, ask me privately if you want to know what "explanation mark free" gives).
infix operator <> : ComparisonPrecedence
extension Equatable {
static func <> (a: Self, b: Self) -> Bool {
a == b ? false : true
}
}
extension Optional {
static func <> (a: Wrapped?, b: _OptionalNilComparisonType) -> Bool {
a == b ? false : true
}
static func <> (a: _OptionalNilComparisonType, b: Wrapped?) -> Bool {
a == b ? false : true
}
}
extension Bool {
var not: Bool {
self == false
}
}
This generally works very well. However I noticed some significant drawback in that I am not getting important warnings (I wish there was a way to force them to be errors instead):
func bar() {
let x = 0
if x != nil { // Warning: Comparing non-optional value of type 'Int' to 'nil' always returns true
print("hello")
}
if x != 0 {
print("hello") // Warning: Will never be executed
}
if !(x == 0) {
print("hello") // Warning: Will never be executed
}
if x <> nil { // no warning
print("hello")
}
if x <> 0 {
print("hello") // no warning
}
if (x == 0).not {
print("hello") // no warning
}
}
Is there a way to get those warnings for my custom operators / functions?