首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >倒计时代码在Swift 2中不起作用

倒计时代码在Swift 2中不起作用
EN

Stack Overflow用户
提问于 2015-10-05 12:26:24
回答 1查看 106关注 0票数 0

我在Swift 1.2中有以下代码:

代码语言:javascript
复制
    //Age

@IBOutlet weak var daysLabel: UILabel!
@IBOutlet weak var monthsLabel: UILabel!
@IBOutlet weak var yearsLabel: UILabel!

@IBAction func birthday(sender:AnyObject){

    var dateComponents = NSDateComponents()

    dateComponents.day = 19
    dateComponents.month = 12
    dateComponents.year = 1999

    let birthDate = NSCalendar(identifier: NSCalendarIdentifierGregorian)!.dateFromComponents(dateComponents)!

    let durationDateComponents = NSCalendar(identifier: NSCalendarIdentifierGregorian)!.components( [.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: birthDate, toDate: NSDate(), options: nil)


     yearsLabel.text = "\(durationDateComponents.year)"
     monthsLabel.text = "\(durationDateComponents.month)"
     daysLabel.text = "\(durationDateComponents.day)"


}

这个用来显示他们离我的生日还有多少天,但这在Swift 2中似乎不起作用。

代码语言:javascript
复制
        let durationDateComponents = NSCalendar(identifier: NSCalendarIdentifierGregorian)!.components( [.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: birthDate, toDate: NSDate(), options: nil)

说"nil与NSCalenderOptions的参数不兼容。

EN

回答 1

Stack Overflow用户

发布于 2015-10-05 12:36:37

从Swift 2开始,NS_OPTIONS (如NSCalendarOptions)作为OptionSetType映射到Swift,提供类似set的接口。特别是,"no options“现在可以指定为[]而不是nil。有关更多详细信息,请参阅此answer

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32941275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档