gpt4 book ai didi

ios - CVCalendarKit - 运算符使用不明确 '=='

转载 作者:行者123 更新时间:2023-11-28 14:53:08 25 4
gpt4 key购买 nike

您好,我正在使用 CVcalendarKit Pod。我正在尝试将我的 Swift 2 代码升级到 Swift 3,但代码存在一些问题。我收到“运算符‘==’的模糊使用。有人有解决方案吗?

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 已经是 EquatableComparable。您不能定义新的比较运算符,因为它们已经在标准库中定义。

不要使用那个 Pod,它已经过时了,而且很多功能已经包含在标准库中(即使 Pod 是新的,一些功能也在标准库中)。

请注意,即使是 CVCalendarKit 中的原始功能也不正确。例如,Date 表示一个时间点,而库声明比较运算符仅适用于年、月和日(类似于库函数 Calendar.compare(_:to:toGranularity :))。

您不需要以下形式的自定义访问器:

let newDate = date.year + 1

当标准库已经给你的时候:

let newDate = Calendar.current.date(byAdding: .year, value: 1, to: date)

更短并不意味着更好。

然而,该 pod 不再维护,功能已移至 CVCalendar ,特别是文件 CVDateCVCalendarManager实现起来比原来的要好一些。

关于ios - CVCalendarKit - 运算符使用不明确 '==',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49638537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com