8
let dateComponents = calendar.components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit, fromDate: date)  

I got error:

'DayCalendarUnit' was deprecated in iOS version 8.0: Use NSCalendarUnitDay instead

But when I replace these names with those suggested by Apple

let dateComponents = calendar.components(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear, fromDate: date)

I get error:

Use of unresolved identifier 'NSCalendarUnitDay' 
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

3 Answers3

18

Along with latest Swift 2.0:

NSCalendarUnit.Day

hence you will now have:

let dateComponents = calendar.components([NSCalendarUnit.Month, NSCalendarUnit.Day, NSCalendarUnit.Year], fromDate: date)
dubemike
  • 2,222
  • 1
  • 15
  • 12
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
16

try this

NSCalendarUnit.CalendarUnitDay
Matthew Chung
  • 1,322
  • 1
  • 19
  • 31
2

Latest Swift works with just .day, .month etc.

Jack
  • 13,571
  • 6
  • 76
  • 98
Raesu
  • 310
  • 2
  • 15