swift 比较运算符方法
代码如下:
// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
// Consider refactoring the code to use the non-optional operators.
func< (lhs: T?,rhs: T?) ->Bool{
switch(lhs, rhs) {
caselet(l?, r?):
returnl < r
case(nil, _?):
return true
default:
return false
}
}
// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
// Consider refactoring the code to use the non-optional operators.
func<= (lhs: T?,rhs: T?) ->Bool{
switch(lhs, rhs) {
caselet(l?, r?):
returnl <= r
default:
return!(rhs < lhs)
}
}
// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
// Consider refactoring the code to use the non-optional operators.
func> (lhs: T?,rhs: T?) ->Bool{
switch(lhs, rhs) {
caselet(l?, r?):
returnl > r
default:
returnrhs < lhs
}
}
// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.
// Consider refactoring the code to use the non-optional operators.
func>= (lhs: T?,rhs: T?) ->Bool{
switch(lhs, rhs) {
caselet(l?, r?):
returnl >= r
default:
return!(lhs < rhs)
}
}






网友评论