Type … ambiguous without more context

折月煮酒 提交于 2019-12-14 01:08:50

问题


On the process of migrating an iOS app to Swift 3.0. Here is one issue I am facing.

First the relevant code:

let calendar = NSCalendar.current,
calendCompo = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: NSDate())

Second the problem:

I am getting this error message, for the second line:

Type of expression is ambiguous without more context

I also tried this code:

let calendar = NSCalendar.current,
calendCompo = calendar.components([.year, .month, .day, .hour, .minute, .second], fromDate: NSDate())

But it did not make any difference.

How do I need to modify the code to make it work? Thanks for any relevant tip.


回答1:


The correct way to achieve that in Swift 3.0 is:

let calendar = NSCalendar.current,
calendCompo = calendar.dateComponents([.Year, .Month, .Day, .Hour, .Minute, .Second], from: NSDate())


来源:https://stackoverflow.com/questions/41158611/type-ambiguous-without-more-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!