//prefix 前缀 操作符在变量前
//postfix 后缀
//infix 中间
//不要和系统冲突即可
prefix operator -!
postfix operator ~~
infix operator !!!
class Person {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
static prefix func -!(lhs: Person) -> Bool {
return lhs.age > 0
}
static postfix func ~~(lhs: Person) -> Bool {
return lhs.age < 0
}
static func !!!(lhs: Person, rhs: Person) -> Bool {
return lhs.age == rhs.age + 1
}
}
let p1 = Person(name: "", age: 2)
let p2 = Person(name: "", age: 1)
//使用:
-!p1
p1~~
p1 !!! p2