将 Swift 语法转换为最新版本时出现错误:
Argument labels '(_:, fromDate:)' do not match any available overloads
在以下行:
let components = calendar.components(componentOptions, fromDate: NSDate())
作为引用,这是其他常量/变量上下文中的行。
let calendar = NSCalendar.current
let componentOptions:NSCalendar.Unit = .weekday
let components = calendar.components(componentOptions, fromDate: NSDate())
var weekday = components.weekday
let days = ["S", "S", "M", "T", "W", "T", "F"]
我的错误到底是什么,我该如何解决?似乎是一个简单的修复,我就是想不通。
谢谢。
更新:
行内:
let components = calendar.components(componentOptions, fromDate: NSDate())
我将 fromDate
更改为 from
并且在一系列 Xcode 推荐的更改之后我得到了:
let components = calendar.dateComponents(componentOptions, from: NSDate() as Date)
但我现在收到错误:
Cannot convert value of type 'NSCalendar.Unit' to expected argument type 'Set<Calendar.Component>'
最佳答案
试试这些行:
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: Date())
关于swift - 更新到 Swift 3 时,参数标签与任何可用的重载错误不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42016554/