gpt4 book ai didi

ios - 我可以在 Apple 文档的何处找到 Set 的选项?

转载 作者:行者123 更新时间:2023-11-28 16:05:30 25 4
gpt4 key购买 nike

在 Xcode 中显示一条错误消息“无法将‘NSCalendar.Unit’类型的值转换为预期的参数类型‘Set’”。

出现此错误的代码行如下:

let dateComponents = NSCalendar.current.dateComponents(NSCalendar.Unit.year, from: <Date>, to: <Date>)

问题是我试过的“NSCalendar.Unit.year”不正确。如何在 Apple 文档中搜索正确的解决方案?我尝试了谷歌搜索,但它会显示各种博客,但我正试图更倾向于从 Apple 的文档中寻找解决方案。

最佳答案

首先,使用日历,而不是 NSCalendar。所以你想与 Calendar.current 交谈。

文档在这里:

https://developer.apple.com/reference/foundation/calendar

你调用的方法在这里:

https://developer.apple.com/reference/foundation/calendar/2292887-datecomponents

其次,只用单位名称。 Swift 已经知道这是一组 Calendar.Component。所以只需说 [.year](一组文字)。

文档在这里:

https://developer.apple.com/reference/foundation/calendar.component

关于ios - 我可以在 Apple 文档的何处找到 Set<Calendar.Component> 的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40372197/

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