简体   繁体   中英

CVCalendarKit - Ambiguous use of operator '=='

Hi im using the CVcalendarKit Pod. Im trying to upgrade my Swift 2 code to Swift 3, but have som issues with the code. Im getting the "Ambiguous use of operator '=='. Anyone with a solution ?

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)
}

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 , specifically the files CVDate and CVCalendarManager which are implemented a bit better than the original.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM