Type … ambiguous without more context

2019-06-25 05:37发布

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条回答
\"骚年 ilove
2楼-- · 2019-06-25 06:34

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())
查看更多
登录 后发表回答