0
@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 .

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Chetrit
  • 33
  • 2
  • 8
  • I am unable to reproduce this error, so could you please elaborate by giving some more code/context. – Eric Aug 16 '17 at 11:14
  • Compare [How to initialize properties that depend on each other](https://stackoverflow.com/questions/25854300/how-to-initialize-properties-that-depend-on-each-other) or [Swift: expected declaration error setting “Label” to a string variable](https://stackoverflow.com/questions/26764266/swift-expected-declaration-error-setting-label-to-a-string-variable) – Martin R Aug 16 '17 at 11:19

1 Answers1

0

You should use lazy var

 @IBOutlet var operateur : UITextField!
    lazy var nbOperateur : String = {
        self.nbOperateur = self.operateur.text ?? ""
        return self.nbOperateur
    }()
Jack
  • 13,571
  • 6
  • 76
  • 98