这个问题在这里已经有了答案:DifferencesinNSDateComponentssyntax?(2个答案)关闭6年前。letdateComponents=calendar.components(.DayCalendarUnit|.MonthCalendarUnit|.YearCalendarUnit,fromDate:date)我得到了错误:'DayCalendarUnit'在iOS8.0版中被弃用:改用NSCalendarUnitDay但是当我用Apple建议的名称替换这些名称时letdateComponents=calendar.components(NSCalendarUn