title: Error when trying to access an instance variable inside another variable of type "Dictionary<String, Double>"
body: <p>I'm trying to create a variable of type <code>Dictionary&lt;String, Double&gt;</code> where one of the value in the dictionary is calculated from an instance variable of the type. </p>
  
  <pre><code>class CalculatorBrain {
      private var accumulator = 0.0
  
      private var operations: Dictionary&lt;String, Double&gt; = [
          "π": M_PI,
          "√": sqrt(accumulator)
      ]
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HLgLY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HLgLY.png" alt="enter image description here"></a></p>
  
  <p>But I have encountered the following error. </p>
  
  <blockquote>
    <p>Cannot use instance member 'accumulator' within property initializer;
    property initializers run before 'self' is available</p>
  </blockquote>
  
  <p>I thought maybe this has something to do with how Swift initialisation order works, so I added keyword <code>lazy</code> to the dictionary variable, so that it will only be initialised when it is used. However, this doesn't work as well.</p>
  
  <p>Why does the error occur and how to make it work?</p>
  
  <pre><code>class CalculatorBrain {
      private var accumulator = 0.0
  
      lazy private var operations: Dictionary&lt;String, Double&gt; = [
          "π": M_PI,
          "√": sqrt(accumulator)
      ]
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/z0JZ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z0JZ2.png" alt="enter image description here"></a></p>