1

I got a problem with Swift 2.0 and NSDateComponents.

let calendar = NSCalendar.currentCalendar()
let components: NSDateComponents = calendar.components([.Hour,
    .Minute, .Second], fromDate: self.dateTime , toDate: NSDate(), options: nil)

I know since Swift 2.0 .Hour | .Minute can no longer be used so tried it with the new way with OptionSetType.

Like answered here: Xcode 7: Can't use CalendarUnitMonth in Swift 2.0, Xcode 7

But it doesn't work. XCode gives me the following error: 'Element.Protocol' does not have a member named 'Hour'

Does anybode have an idea on how to fix it?

Community
  • 1
  • 1
mort3m
  • 481
  • 1
  • 7
  • 17

1 Answers1

1

Despite the error message, it appears that Xcode does not like your options: nil. Try using [] instead.

calendar.components([.Hour, .Minute, .Second], fromDate: NSDate(),
    toDate: NSDate(), options: nil) // error

calendar.components([.Hour], fromDate: NSDate(),
    toDate: NSDate(), options: []) // no error
Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
MirekE
  • 11,515
  • 5
  • 35
  • 28
  • Thanks, I tried everything because I thought the problem was the first parameter.. never thought about the last one! Everything works fine now! – mort3m Jul 18 '15 at 01:09