swift - 更新到 Swift 3 时,参数标签与任何可用的重载错误不匹配

标签 swift swift3

将 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/

相关文章:

ios - 无法将类对象分配给 Swift 3 中另一个类对象的字典成员

SWIFT 3 - 将整数转换为字符

ios - 如何在应用程序重新打开时重置本地通知

ios - UINavigationController topViewController 未显示

ios - 如何在 Alamofire 4 中进行多部分表单数据上传?

ios - 按高度比例放置uiview,如何?

ios - 在 Swift/XCode 8 中从 subview 更改父 View ?

swift - 从字典生成章节标题 [Swift 3]

ios - swift 将 CLLocation 转换为 CLLocationCoordinate2D

swift - 检查选项数组是否为零