Type ... ambiguous without additional context

In the process of migrating your iOS application to Swift 3.0. Here is one of the issues that I have encountered.

First, the corresponding code:

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

Secondly, the problem:

I get 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 that didn't make any difference.

How do I change the code to make it work? Thanks for any relevant feedback.

+4
source share
1 answer

The correct way to achieve this in Swift 3.0 is :

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

Source: https://habr.com/ru/post/1663816/


All Articles