25

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 requirement of protocol 'RangeReplaceableCollection'.

Saurabh Sharma
  • 1,671
  • 2
  • 13
  • 16

6 Answers6

69

Append it to extension ChartDataSet: RangeReplaceableCollection

public func replaceSubrange<C>(_ subrange: Swift.Range<Int>, with newElements: C) where C : Collection, ChartDataEntry == C.Element {
    entries.replaceSubrange(subrange, with: newElements)
    notifyDataSetChanged()
}
Saurabh Sharma
  • 1,671
  • 2
  • 13
  • 16
  • I have a bizarre error now. When I do the change above, my charts code compiles as it should, but Xcode reports that *a completely different package* is now missing from the project! wtf? The other package is still there exactly where it was before. – john elemans Nov 23 '22 at 20:18
  • 1
    Thanks for the Answer its like life saving. – Adarsh KC Mar 29 '23 at 04:49
1

It was fixed on Master brunch

Add master brunch to your project, instead of "Up to next major version" in SPM. And use in CacaoPods: `

pod 'Charts', :git => 'https://github.com/danielgindi/Charts.git', :branch => 'master'

Artsem Sharubin
  • 388
  • 3
  • 10
1

I am using Xcode 14.2. I removed the Charts from the podFile and then added it via SPM. However, beware to only include Charts (4.1.0) and not Dynamic Charts. The latter will result in a "Module not found" error for Algorithms

0

I have newly installed Xcode 14.1 and found multiple error on the Charts cocoapod library. Found multiple solutions online but none worked fully and made sense to me. Finally using swift package manager for Charts solved the problem like charm.

Solution - Remove Charts pod from Podfile and add SPM (Swift Package Manager) for the same using url:

https://github.com/danielgindi/Charts.git

make sure you change version to:

upToNextMajor(from: "4.1.0")

enter image description here

Hope it helps anyone who was in same problem. Good luck!

mAc
  • 2,434
  • 2
  • 22
  • 39
0

Same thing happened to me. I am using the swift package manager to import charts and the error went away after updating the swift package manager. However, the charts version remains 4.0. Packages other than charts may be the culprit.

0

Increase the platform version to platform :ios, '12.0' or above in your Podfile. And then add pod 'Charts' into the pod file. Then hit pod install in the terminal, the version installed will be 14.0.1 which is currently the latest, this will resolve the issue. If you face issue with initializing charts after the above step then add this piece of code to resolve the error,

let pieChartDataSet = PieChartDataSet(entries: dataEntries, label: "") 
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
puneeth
  • 743
  • 7
  • 8