参见英文答案 >
Differences in NSDateComponents syntax?2个
let dateComponents = calendar.components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit,fromDate: date)
我收到了错误:
iOS版8.0中不推荐使用“DayCalendarUnit”:改为使用NSCalendarUnitDay
let dateComponents = calendar.components(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear,fromDate: date)
我收到错误:
Use of unresolved identifier 'NSCalendarUnitDay'
解决方法
与最新的Swift 2.0一起:
NSCalendarUnit.Day
因此你现在将拥有:
let dateComponents = calendar.components([NSCalendarUnit.Month,NSCalendarUnit.Day,NSCalendarUnit.Year],fromDate: date)