Xcode 14.2:Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection'

2023年2月1日 917点热度 1人点赞 0条评论

将Xcode更新至14.* 之后,如果项目中集成了Charts,在编译过程中ChartDataSet文件会报以下错误,导致无法编译;

Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection'

Unavailable instance method 'replaceSubrange(_:with:)' was used to satisfy a requirement of protocol 'RangeReplaceableCollection'

 

解决方法:

⚠️:这是一个临时解决方法,最终的解决方案还需要Charts更新之后修复,目前看到最新的4.1.0版用来解决此问题,但是还会导致其他问题,所以可以先采用以下方法临时更新,等待Charts官方修复(虽然时间过去半年了还没有修复)

 

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

将上面代码加入Charts中的ChartDataSet文件中,如图所示位置:

Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection'

Type 'ChartDataSet' does not conform to protocol 'RangeReplaceableCollection'

 


参考:https://github.com/danielgindi/Charts/issues/4860#issuecomment-1176949576

 

帮助教程

提供最新的帮助教程,方便使用。

文章评论