xcode 'DayCalendarUnit 已被弃用。改用 NSCalendarUnitDay ' 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29536041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:56:13  来源:igfitidea点击:

'DayCalendarUnit was deprecated. Use NSCalendarUnitDay instead' doesn't work

iosxcodeswiftnscalendar

提问by Bart?omiej Semańczyk

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

I got error:

我有错误:

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

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

But when I replace these names with those suggested by Apple

但是当我用 Apple 建议的名称替换这些名称时

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

I get error:

我得到错误:

Use of unresolved identifier 'NSCalendarUnitDay' 

回答by Bart?omiej Semańczyk

Along with latest Swift 2.0:

随着最新的 Swift 2.0:

NSCalendarUnit.Day

hence you will now have:

因此,您现在将拥有:

let dateComponents = calendar.components([NSCalendarUnit.Month, NSCalendarUnit.Day, NSCalendarUnit.Year], fromDate: date)

回答by Matthew Chung

try this

尝试这个

NSCalendarUnit.CalendarUnitDay

回答by Raesu

Latest Swift works with just .day, .monthetc.

最新斯威夫特的作品只.day.month等等。