Access global var

0

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

    
asked by anonymous 05.10.2015 / 19:44

1 answer

2

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

    
05.10.2015 / 19:50