Use of unresolved identifier NSCalendarUnitDay

╄→尐↘猪︶ㄣ 提交于 2019-11-28 04:19:50

问题


I just updated Xcode to its 6.3 version.

Except all the fixes I have to make regarding as (mainly), I have some warnings that just appeared (which is weird as it states it is since iOS 8.0).

My code

NSCalendar.currentCalendar().compareDate(self, toDate: date, toUnitGranularity: .DayCalendarUnit) == .OrderedAscending

is now shows a warning

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

Fine, then I'll change .DayCalendarUnit by NSCalendarUnitDay

Now I get an error saying:

Use of unresolved identifier 'NSCalendarUnitDay'

I'm confuse, can someone explain me what's wrong and how to fix it?


回答1:


Use .CalendarUnitDay. NSCalendar is a native Objective-C framework and the error messages aren't for swift.




回答2:


I think Apple thought the name of those units weren't meaningful like .DayCalendarUnit, so they have modified it to sound more sensible and explanative as .CalendarUnitDay.

Similar modifications have been done in Objective-C. NSDayCalendarUnit is deprecated and you have to use NSCalendarUnitDay.

The problem in your case is that you are receiving deprecation warning of Objective-C instead of Swift. We hope Apple fixes it soon.

Hope that explains...




回答3:


in Xcode 7.3 use .Day which is a property of NSCalendarUnit struct



来源:https://stackoverflow.com/questions/29529925/use-of-unresolved-identifier-nscalendarunitday

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!