倒计时代码在Swift 2中不起作用
我在Swift 1.2中有以下代码:倒计时代码在Swift 2中不起作用,swift,swift2,countdown,Swift,Swift2,Countdown,我在Swift 1.2中有以下代码: //Age @IBOutlet weak var daysLabel: UILabel! @IBOutlet weak var monthsLabel: UILabel! @IBOutlet weak var yearsLabel: UILabel! @IBAction func birthday(sender:AnyObject){ var dateComponents = NSDateComponents() dateCo
//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中似乎不起作用。我在一个地方出错了
let durationDateComponents = NSCalendar(identifier: NSCalendarIdentifierGregorian)!.components( [.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: birthDate, toDate: NSDate(), options: nil)
说nil与NSCalendarOptions的参数不兼容。从Swift 2开始,NSCalendarOptions等NS_选项作为选项集映射到Swift,该选项集提供类似集合的接口。特别是,现在不能将任何选项指定为[]而不是nil。 有关更多详细信息,请参见此