首页 > 解决方案 > 如何将数据从超类传递到子类?

问题描述

我使用 segue 从 FirstViewController 发送数据,我在 ViewController 中接收它,我想从子类访问位于超类中的变量。这是我现在的代码

class ViewController: UIViewController {


public var count: String = ""

}

class Counter  {

func loadData(){

print(count)
}
}

结果为空或nil 谢谢

标签: iosswift

解决方案


类在继承方面与类没有Counter关系。ViewController这不是超类/子类关系。

在类中定义ViewController类不会给它任何访问ViewController实例属性的权限


推荐阅读