How to override internal framework method in application (outside framework)

青春壹個敷衍的年華 提交于 2019-12-08 15:58:44

问题


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) {
             ...
   }
}

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) {
             ...
   }
}

but when I'm trying to override Xcode gives me error:

Method does not override any method from its superclass

Because it's internal.

There is also one internal variable with I need access to and same as above Xcode can't see it.


回答1:


You should use the open keyword instead of public

Check the the Access Control here: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html



来源:https://stackoverflow.com/questions/35033301/how-to-override-internal-framework-method-in-application-outside-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!