title: What is the right way to override a property in a subclass in Swift?
body: <p>I also stumbled upon this question, however, there is no definitive answer</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/24087011/ambiguous-use-of-propertyname-error-given-overridden-property-with-didset-ob">&quot;Ambiguous use of &#39;propertyName&#39;&quot; error given overridden property with didSet observer</a></p>
  </blockquote>
  
  <p><strong>Problem:</strong> I would like to override a property in a subclass.</p>
  
  <p>Let me illustrate the problem with an example: </p>
  
  <p>I have a class called <code>A</code> and a subclass thereof called <code>B</code>.</p>
  
  <h3>Class A</h3>
  
  <pre><code>class A {
  
      var someStoredProperty : Int? 
  
  }
  </code></pre>
  
  <h3>Class B</h3> 
  
  <pre><code>class B : A{
  
      override var someStoredProperty : Int?{
  
          willSet{
  
              //add to superclass's setter 
              someStoredProperty = newValue! + 10
          }
  
      }
  
  }
  </code></pre>
  
  <p>As soon as I try to set the inherited property of <code>B</code> </p>
  
  <pre><code>var b = B()
  b.someStoredValue = 10 // Ambiguous use of someStoredProperty
  </code></pre>
  
  <p>the compiler tells me </p>
  
  <p><code>Ambiguous use of someStoredProperty</code></p>
  
  <p>Why is that ? </p>
  
  <h2> Update </h2>
  
  <pre><code>class TableViewRow{
  
      typealias ClickAction = (tableView:UITableView, indexPath:NSIndexPath) -&gt; Void
      var clickAction : ClickAction?
  }
  
  class SwitchTableViewRow: TableViewRow {
  
      override var clickAction : ClickAction? {
  
          didSet{
  
              //override setter
          }
  
      }
  
  }
  </code></pre>
  
  <p>Usage: </p>
  
  <pre><code>var switchRow = SwitchTableViewRow()
  switchRow.clickAction = {    
         //^
         //|
         //|
   //ambiguous use of clickAction
  [unowned self, unowned switchRow] (tableView: UITableView, indexPath: NSIndexPath) in
  
      //do something
  
  }
  </code></pre>