title: In Swift, is there a better way to initialize a "get" only variable?
body: <p>Say I have a class, <code>MyClass</code>, and it can be in either a valid or invalid state. So I keep track of this with a bool called <code>isValid</code>. I want this value initialized to <code>false</code> until the class's <code>initialize</code> function is called. The <code>initialize</code> (and a corresponding <code>reset</code> function) will directly be able to change the value of the <code>isValid</code> bool. This is what I have set up so far:</p>
  
  <pre><code>class MyClass {
  
    private var _isValid: Bool = false
    var isValid: Bool {
      get { return _isValid }
    }
  
  // any required init functions
  
    func initialize() {
      // init stuff
      _isValid = true
    }
  
    func reset() {
      // reset stuff
      _isValid = false
    }
  
  }
  </code></pre>
  
  <p>So is this the best way to do it, or is there any way I can remove the second private var and somehow allow just the class functions to modify a read only public facing variable?</p>