Chetrit Chetrit - 2 years ago 119
Swift Question

Error expected declaration on var declaration

@IBOutlet var operateur : UITextField!
var nbOperateur : String?
nbOperateur = operateur.text


I can't understand why it is "Expected Declaration" , operateur can be only "+" or "-" or "%" or "x" or "/" , please I need help , thanks .

Answer Source

You should use lazy var

 @IBOutlet var operateur : UITextField!
    lazy var nbOperateur : String = {
        self.nbOperateur = self.operateur.text ?? ""
        return self.nbOperateur
    }()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download