iOS 개발일기

[Swift] Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection' 에러 해결 방법 본문

iOS/Swift

[Swift] Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection' 에러 해결 방법

맨날 까먹으니 적어두자 2024. 9. 25. 21:31

 

pod 업데이트 후 Charts 라이브러리에 에러가 발생하여 확인해보니 프로토콜을 준수하지 않는다고 합니다.

두번째 에러 내용을 보고 'replaceSubrange(_:with:)' 메소드를 추가하여야 된다 생각하여 메서드 내 작성할 내용을 알아보기 위해 검색을 해본 결과

public func replaceSubrange<C>(
    _ subrange: Swift.Range<Index>, 
    with newElements: C
) where C : Collection, Element == C.Element {
    entries.replaceSubrange(subrange, with: newElements)
    notifyDataSetChanged()
}

 

위와 같이 작성하여 추가해주면 된다는 것을 확인했습니다.

 

 

 

참조

https://stackoverflow.com/questions/74010925/charts-not-compile-on-xcode-14

 

Charts not compile on Xcode 14

I am facing following errors in library - Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection' Unavailable instance method 'replaceSubrange(_:with:)' was used to satisfy a

stackoverflow.com

 

https://github.com/ChartsOrg/Charts/blob/c3701a4e5ce111c29dd7af9e19e6a346ccf0ad52/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift#L427-L431

 

Charts/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift at c3701a4e5ce111c29dd7af9e19e6a346ccf0ad52 · ChartsOrg/C

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart. - ChartsOrg/Charts

github.com