问题描述
在Swift中进行子类化时,是否仍要覆盖内部框架方法?前任.超类
Is there anyway to override internal framework method when subclassing in Swift? Ex. Superclass
public class BarChartRenderer: ChartDataRendererBase {
internal func drawDataSet(context context: CGContext, dataSet: BarChartDataSet, index: Int) {
...
}
}
我想重写此方法以绘制与dataSet不同的图形(iOS图表)
and I want to override this method to draw differently that dataSet (iOS-Charts)
public class ESBarChartRenderer: BarChartRenderer {
overide func drawDataSet(context context: CGContext, dataSet: BarChartDataSet, index: Int) {
...
}
}
但是当我尝试覆盖Xcode时出现错误:
but when I'm trying to override Xcode gives me error:
因为它是内部的.
还有一个我需要访问的内部变量,与上面的Xcode一样看不到它.
There is also one internal variable with I need access to and same as above Xcode can't see it.
推荐答案
您应该使用open
关键字而不是public
You should use the open
keyword instead of public
在此处检查访问控制: https://developer.apple.com/library/内容/文档/Swift/概念/Swift_Programming_Language/AccessControl.html
Check the the Access Control here:https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html
这篇关于如何在应用程序(外部框架)中覆盖内部框架方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!