类型...模棱两可,无需更多上下文 [英] Type ... ambiguous without more context

查看:219
本文介绍了类型...模棱两可,无需更多上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将iOS应用迁移到Swift 3.0的过程.这是我面临的一个问题.

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

首先输入相关代码:

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

第二个问题:

对于第二行,我收到此错误消息:

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

Type of expression is ambiguous without more context

我也尝试了以下代码:

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

但这没什么区别.

我需要如何修改代码才能使其正常工作? 感谢您提供任何相关提示.

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

推荐答案

Swift 3.0 中实现此目标的正确方法是:

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())

这篇关于类型...模棱两可,无需更多上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆