title: Swift: Default Initializer for Computed Property
body: <p>It seems like I can't give a computed property a default value using the Default Initializers method that can be used for Stored Properties. Here's a use case where I would need this:</p>
  
  <pre><code>@IBDesignable public class MyRoundedCornersView: UIView {
  
      @IBInspectable var cornerRadius: CGFloat {
          get {
              return self.layer.cornerRadius
          }
          set {
              self.layer.cornerRadius = newValue
          }
      }
  
  }
  </code></pre>
  
  <p>I'd like to give the cornerRadius a default value. But the following doesn't work (just added <code>= 8.0</code>):</p>
  
  <pre><code>@IBDesignable public class MyRoundedCornersView: UIView {
  
      @IBInspectable var cornerRadius: CGFloat = 8.0 {
          get {
              return self.layer.cornerRadius
          }
          set {
              self.layer.cornerRadius = newValue
          }
      }
  
  }
  </code></pre>
  
  <p>I get the not so useful <code>'(() -&gt; () -&gt; $T1) -&gt; $T2' is not identical to 'Double'</code> error. I looked up <a href="https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html#//apple_ref/doc/uid/TP40014097-CH18-XID_296" rel="noreferrer">here</a> to find out how to do this but it seems Apple doesn't support default values for computed properties. At least I couldn't find anything.</p>
  
  <p>So how can I still make sure that I have a default value for my property? <a href="https://stackoverflow.com/questions/24940855/swift-computed-properties-cannot-be-used-in-init">This thread</a> says it isn't possible within the init method either – but even if, I'd like to keep the default value near my property definition. Does anyone have an idea?</p>