2016-11-02 3 views
0

Xcode에서 " 'NSCalendar.Unit'유형의 값을 'Set'유형의 예상 인수 유형으로 변환 할 수 없습니다라는 오류가 표시됩니다.Apple 설명서에서 <Calendar.Component> 설정 옵션을 어디에서 찾을 수 있습니까?

let dateComponents = NSCalendar.current.dateComponents(NSCalendar.Unit.year, from: <Date>, to: <Date>) 

문제는 내가 그 잘못 했어요 "NSCalendar.Unit.year"입니다 :

이 오류를 제시 코드의 라인은 다음과 같다. Apple의 설명서에서 올바른 솔루션을 검색하려면 어떻게합니까? 나는 Google 검색을 시도했지만 다양한 블로그를 가져 오지만, Apple의 문서에서 솔루션을 찾는 경향이 점점 커지고 있습니다.

답변

1

우선 NSCalendar가 아닌 Calendar를 사용하십시오. 그래서 Calendar.current에게 말하고 싶습니다.

문서는 여기에 있습니다 :

https://developer.apple.com/reference/foundation/calendar

당신이 전화하는 방법은 여기에 있습니다 :

https://developer.apple.com/reference/foundation/calendar/2292887-datecomponents

둘째, 그냥 장치의 이름을 사용합니다. Swift는 이미 이것이 Calendar.Component의 집합임을 알고 있습니다. 따라서 [.year] (리터럴 집합)이라고 말하면됩니다.

문서는 여기에 있습니다 :

https://developer.apple.com/reference/foundation/calendar.component