如何在应用程序(外部框架)中覆盖内部框架方法 [英] How to override internal framework method in application (outside framework)

查看:110
本文介绍了如何在应用程序(外部框架)中覆盖内部框架方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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:

方法不会覆盖其超类中的任何方法

Method does not override any method from its superclass

因为它是内部的.

还有一个我需要访问的内部变量,与上面的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

这篇关于如何在应用程序(外部框架)中覆盖内部框架方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆