Where is the problem accessing a ViewController: UIViewController label (here: outlet called timerLabel)from AnotherClass. I would like to set a text.
class AnotherClass{
//[...]
func updateTimeLabel(){
// To Solve!!!*******
//class name is ViewController?
let myLabel = ViewController.timerLabel
myLabel.text = "HiDuEi"
}
//[...]
// error message is:
//Instance member 'timerLabel' cannot be used on type 'ViewController'
}
how can I access the ViewController class (called ViewController) properly and access my outlet (a label) there, called timerLabel? THX
ViewControlleris a type, not an instance of the object. You need to somehow get a reference to your ViewController instance and then access the label. E.g.Note that this above creates a new instance, it's hard to say where your other viewController is created and how to access it from the code you posted.