gpt4 book ai didi

swift - Date.addingTimeInterval(_ :) and Date. advanced(by :)?)有什么区别

转载 作者:行者123 更新时间:2023-12-04 16:38:12 26 4
gpt4 key购买 nike

基金会Date struct 提供了 Date.addingTimeInterval(_:)Date.advanced(by:)这看起来在功能上是相同的,但显然是不同的方法。它们之间实际上有区别还是它们最终相同?
查看文档,advanced(by:)缺少任何东西,而且 addingTimeInterval(_:)只说

The value to add, in seconds.


与 NSDate 相比时, advanced(by:)完全失踪。剧情变厚了!

最佳答案

.addingTimeInterval(_:)是一个长期存在的方法,来自 ObjC NSDate。 .advanced(by:)存在以匹配 Swift 中的 Strideable 一致性。 Date 同样具有 Stride 类型别名。
也就是说,Date 实际上并不符合 Strideable,and this has been discussed and generally rejected .
Strideable 伪一致性似乎已添加为 a large merge from Xcode 11.4 的一部分在名为 Schedulers+Date 的扩展中这似乎是Combine(不是开源的)的一部分。我在论坛上没有看到任何讨论,except for a note that it broke existing code .变更说明:

// Date cannot conform to Strideable per rdar://35158274
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Date /* : Strideable */ {
我的预感是在 Combine 内部的某个地方,有 Date 到 Strideable 的追溯一致性。您只需提出要求即可获得相同的结果:
extension Date: Strideable {}
感觉 Swift stdlib 团队接受了 Date 不应该是 Strideable(我同意这个推理,因为它会引起很多常见的日期错误),但是 Apple 的其他一些团队想要它并且无论如何将钩子(Hook)放入 stdlib,没有放入一致性。

关于swift - Date.addingTimeInterval(_ :) and Date. advanced(by :)?)有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66321489/

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