是否可以从另一个模块编辑 public 变量的值?

Is it possible to edit the value of a public variable from another module?

您可以从另一个模块编辑 public 变量的值吗?或者该变量是否必须打开。


我对swift3中public/open的理解是:

你绝对可以!这是您可以完成它的好方法:

在包含您要操作的变量的模块中:

// Must be declared globally
public var someValue = "hi"

在您希望操作变量的不同模块中:

// Initialize the module that holds the variable you want to manipulate
var myModule = SomeModule()

// Manipulate the variable (someValue)
myModule.someValue = "bye"

变量 someValue 现在的值为 "bye"