I have the following problem: I have the following code
var myGlobal : String
func nomeDaFuncao () {
// Preciso acessar a global
myGlobal = "fff"
}
How can I access the global within a function or an action? Thanks
I have the following problem: I have the following code
var myGlobal : String
func nomeDaFuncao () {
// Preciso acessar a global
myGlobal = "fff"
}
How can I access the global within a function or an action? Thanks
You can use self
if you use the attribute in the same class
self.myGlobal = "VALOR"
Example:
class ViewController: UIViewController {
var myGlobal : String?
override func viewDidLoad() {
super.viewDidLoad()
self.myGlobal = "Teste"
}
}
Remember to use ?
for non-mandatory attributes and !
for required taxes