Swift 2.0日历组件错误 [英] Swift 2.0 calendar components error

查看:130
本文介绍了Swift 2.0日历组件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在swift 2.0中遇到此错误

Hi I get this error in swift 2.0

无法使用类型'的参数列表调用'components'(NSCalendarUnit,fromDate:NSDate?,toDate:NSDate? ,options:nil)'

Cannot invoke 'components' with an argument list of type '(NSCalendarUnit, fromDate: NSDate?, toDate: NSDate?, options: nil)'

var hoy = dataFormatter.stringFromDate(NSDate())
        var despues = dataFormatter.stringFromDate(fecha)
        var calHoy = dataFormatter.dateFromString(hoy)
        var calcDesp = dataFormatter.dateFromString(despues)
        let cal = NSCalendar.currentCalendar()
        let unit:NSCalendarUnit = .Day
        let components = cal.components(unit, fromDate: calcDesp, toDate: calHoy, options: nil) 


推荐答案

从Swift 2开始, NS_OPTIONS (例如 NSCalendarOptions )作为 OptionSetType
映射到Swift,它提供类似集合的接口。特别是,无选项
现在可以指定为 [] 而不是 nil

As of Swift 2, NS_OPTIONS (such as NSCalendarOptions) are mapped to Swift as a OptionSetType which offers a set-like interface. In particular, "no options" can now be specified as [] instead of nil:

let components = cal.components(unit, fromDate: calcDesp!, toDate: calHoy!,
                               options: []) 

另见 Swift 2.0-Binary Operator|"无法应用于两个UIUserNotificationType操作数
以及最近添加的如何在Swift中创建NS_OPTIONS样式的位掩码枚举?以获取更多信息。

See also Swift 2.0 - Binary Operator "|" cannot be applied to two UIUserNotificationType operands and the recently added answers to How to create NS_OPTIONS-style bitmask enumerations in Swift? for more information.

这篇关于Swift 2.0日历组件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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