title: Computed read-only property vs function in Swift
body: <p>In the Introduction to Swift WWDC session, a read-only property <code>description</code> is demonstrated:</p>
  <pre class="lang-swift prettyprint-override"><code>class Vehicle {
      var numberOfWheels = 0
      var description: String {
          return &quot;\(numberOfWheels) wheels&quot;
      }
  }
  
  let vehicle = Vehicle()
  println(vehicle.description)
  </code></pre>
  <p>Are there any implications to choosing the above approach over using a method instead:</p>
  <pre class="lang-swift prettyprint-override"><code>class Vehicle {
      var numberOfWheels = 0
      func description() -&gt; String {
          return &quot;\(numberOfWheels) wheels&quot;
      }
  }
  
  let vehicle = Vehicle()
  println(vehicle.description())
  </code></pre>
  <p>It seems to me that the most obvious reasons for choosing a read-only computed property are:</p>
  <ul>
  <li><strong>Semantics</strong> - in this example it makes sense for <code>description</code> to be a property of the class, rather than an action it performs.</li>
  <li><strong>Brevity/Clarity</strong> - prevents the need to use empty parentheses when getting the value.</li>
  </ul>
  <p>Clearly the above example is overly simple, but are there other good reasons to choose one over the other? For example, are there some features of functions or properties that would guide your decision of which to use?</p>
  <hr />
  <p><em>N.B. At first glance this seems like quite a common OOP question, but I'm keen to know of any Swift-specific features that would guide best practice when using this language.</em></p>