为了账号安全,请及时绑定邮箱和手机立即绑定

Warning:'YearCalendarUnit' was deprecated in iOS version 8.0: Use NSCalendarUnitYear instead

代码:

components(NSCalendarUnit.YearCalendarUnit, fromDate: <#NSDate#>, toDate: <#NSDate#>, options: <#NSCalendarOptions#>)

请问一下老师这个Warning该怎么处理?

正在回答

6 回答

语法更新了,用components([.Year], fromDate: <#NSDate#>, toDate: <#NSDate#>, options: <#NSCalendarOptions#>)就OK

2 回复 有任何疑惑可以回复我~

问题已经解决了,用NSYearCalendarUnit就ok了,虽然会有警告,但是程序可以运行

0 回复 有任何疑惑可以回复我~

大神的封装是何等的重要!原谅我说一句没用的话,但我觉得这样的代码看看就行,没必要自己写,费力不讨好



0 回复 有任何疑惑可以回复我~

第一个参数改成

NSCalendarUnit.CalendarUnitYear

就好了。

1 回复 有任何疑惑可以回复我~
#1

我心依旧130857

感觉又更新了,还是不行
2015-09-17 回复 有任何疑惑可以回复我~
#2

qq_Lu_7

还是不对Type 'NSCalendarUnit' has no member 'CalendarUnitYear'
2015-09-25 回复 有任何疑惑可以回复我~

你仔细看enum NSCalendarUnit的定义,在一开始有新的定义,我觉得应该是消息提示的有错误,应该是下面我标黑体的CalendarUnitYear。你怎么看?

struct NSCalendarUnit : RawOptionSetType {

    init(_ rawValue: UInt)

    init(rawValue: UInt)

    

    static var CalendarUnitEra: NSCalendarUnit { get }

    static var CalendarUnitYear: NSCalendarUnit { get }

    static var CalendarUnitMonth: NSCalendarUnit { get }

    static var CalendarUnitDay: NSCalendarUnit { get }

    static var CalendarUnitHour: NSCalendarUnit { get }

    static var CalendarUnitMinute: NSCalendarUnit { get }

 ............................

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitEra instead")

    static var EraCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitYear instead")

    static var YearCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitMonth instead")

    static var MonthCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitDay instead")

    static var DayCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitHour instead")

    static var HourCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitMinute instead")

    static var MinuteCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitSecond instead")

    static var SecondCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitWeekOfMonth or NSCalendarUnitWeekOfYear, depending on which you mean")

    static var WeekCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitWeekday instead")

    static var WeekdayCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=2.0, deprecated=8.0, message="Use NSCalendarUnitWeekdayOrdinal instead")

    static var WeekdayOrdinalCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=4.0, deprecated=8.0, message="Use NSCalendarUnitQuarter instead")

    static var QuarterCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=5.0, deprecated=8.0, message="Use NSCalendarUnitWeekOfMonth instead")

    static var WeekOfMonthCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=5.0, deprecated=8.0, message="Use NSCalendarUnitWeekOfYear instead")

    static var WeekOfYearCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=5.0, deprecated=8.0, message="Use NSCalendarUnitYearForWeekOfYear instead")

    static var YearForWeekOfYearCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=4.0, deprecated=8.0, message="Use NSCalendarUnitCalendar instead")

    static var CalendarCalendarUnit: NSCalendarUnit { get }

    @availability(iOS, introduced=4.0, deprecated=8.0, message="Use NSCalendarUnitTimeZone instead")

    static var TimeZoneCalendarUnit: NSCalendarUnit { get }

}


0 回复 有任何疑惑可以回复我~
#1

眼中无她却有灯笼椒

能不能简单说呀,像我从java直接学swift有点不明白
2015-05-12 回复 有任何疑惑可以回复我~

没有和我一样问题的同学吗?

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
使用Swift开发iOS8 App实战
  • 参与学习       62613    人
  • 解答问题       541    个

通过苹果最新Swift语言开发iOSApp,从零开始学习iOS的开发

进入课程

Warning:'YearCalendarUnit' was deprecated in iOS version 8.0: Use NSCalendarUnitYear instead

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信