我在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()
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与NSCalenderOptions的参数不兼容。
发布于 2015-10-05 12:36:37
从Swift 2开始,NS_OPTIONS (如NSCalendarOptions)作为OptionSetType映射到Swift,提供类似set的接口。特别是,"no options“现在可以指定为[]而不是nil。有关更多详细信息,请参阅此answer。
https://stackoverflow.com/questions/32941275
复制相似问题