您好我正在使用CVcalendarKit Pod。我试图将我的Swift 2代码升级到Swift 3,但是代码有som问题。我得到了"模糊地使用运算符' =='。有解决方案的人吗?
public func == (lhs: Date, rhs: Date) -> Bool {
return compareWithOperation({ $0 == $1 }, resultMerge: { $0 && $1 && $2 })(lhs, rhs)
}
public func >= (lhs: Date, rhs: Date) -> Bool {
return compareWithOperation({ $0 > $1 || lhs == rhs }, resultMerge: { $0 || $1 || $2 })(lhs, rhs)
}
public func <= (lhs: Date, rhs: Date) -> Bool {
return compareWithOperation({ $0 < $1 || lhs == rhs }, resultMerge: { $0 || $1 || $2 })(lhs, rhs)
}
public func != (lhs: Date, rhs: Date) -> Bool {
return !(lhs == rhs)
}
答案 0 :(得分:1)
Date
is already Equatable
and Comparable
. You cannot define new comparison operators because they are already defined in the standard library.
Don't use that Pod, it's dangerously outdated and a lot of the functionality is already included in the standard library (some of the functionality was in the standard library even when the pod was new).
Note that even the original functionality in CVCalendarKit
was incorrect. For example, a Date
represents a point in time while the library declared the comparison operator to only work on years, months and days (similar to library function Calendar.compare(_:to:toGranularity:)
).
You don't need custom accessors in the form of:
let newDate = date.year + 1
when the standard library is already giving you:
let newDate = Calendar.current.date(byAdding: .year, value: 1, to: date)
Shorter does not mean better.
Nevertheless, the pod is no longer maintained and the functionality was moved to CVCalendar的情况下调用LightBox onclick,特别是文件CVDate和CVCalendarManager,它们的实现方式比原始文件好一些。