title: Overriding getter in Swift
body: <p>I have a situation where I need to override the getter of a property.</p>
  
  <p>Let's say we have:
  </p>
  
  <pre><code>public class MyBaseClass {
      private var _name: String
      public internal(set) var name: String {
          get {
              return self._name
          }
          set {
              self._name = newValue
          }
      }
  }
  </code></pre>
  
  <p>Nothing really fancy, I guess.</p>
  
  <p>Now, if I try to override the getter in a derived class:
  </p>
  
  <pre><code>public class MyDerivedClass: MyBaseClass {
      public var name: String {
          get {
              return "Derived - \(super.name)"
          }
      }
  }
  </code></pre>
  
  <p>I get the compile error: <em>Cannot override mutable property with read-only property 'name'</em>.</p>
  
  <p>If I try to add the setter and overriding it:
  </p>
  
  <pre><code>public class MyDerivedClass: MyBaseClass {
      public internal(set) var name: String {
          get {
              return "Derived - \(super.name)"
          }
          set {
              super.name = newValue
          }
      }
  }
  </code></pre>
  
  <p>I get the error: <em>Setter of overriding var must be as accessible as the declaration it overrides</em>.</p>
  
  <p>And if I try the following:
  </p>
  
  <pre><code>public class MyDerivedClass: MyBaseClass {
      public internal(set) var name: String {
          get {
              return "Derived - \(super.name)"
          }
      }
  }
  </code></pre>
  
  <p>Then, the compiler crashes...</p>
  
  <p>How can I achieve to override only the getter ?</p>