假设在ViewController类中有一个全局字符串变量。在此ViewController类的另一个扩展文件(ViewControllerExtension.swift)中,我希望能够在函数内对此全局变量进行调整。引用UIViewController中的全局字符串变量扩展名
眼下,存在其中需要全局字符串变量作为输入的扩展功能:
func doSomething(inputString: String){
//something is being done and the adjustment will be reflected in the ViewController instance.
}
我的问题是:
- 是否有可以访问的一种方式ViewController的全局字符串变量,而不必通过函数来引用它,因为它的输入?
- 什么是一个好设计的方式去做这件事?经验丰富的程序员如何去解决这个问题?
在此先感谢。