0

I have the following code in 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)"


}

and this used to display how many days their were to my birthday but this doesn't seem to be working in Swift 2. I get an error at

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

saying "nil isn't compatible with an argument of NSCalenderOptions.

Amit Kalra
  • 4,085
  • 6
  • 28
  • 44

1 Answers1

0

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. See this answer for more details.

Community
  • 1
  • 1
Imran
  • 2,985
  • 19
  • 33