title: Swift extension for protocol conformance on object in framework causes infinite loop
body: <p>The problem: A model object is defined in a framework, a protocol is defined in the app target. The app target has knowledge of the framework, but not vice-versa, so the protocol conformance can't be in the model object's declaration. </p>
  
  <p>However, the model object already has the majority of the fields that are needed to fulfill the protocol (mostly var {get} declarations), and -- this is the rub, apparently -- those fields have the same names. There are about 20 properties in the real model. </p>
  
  <p>Unsurprisingly, the following pattern produces an infinite loop: </p>
  
  <pre><code>//Framework Target:  
  
  public struct Book {
      public let numberOfPages : Int
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>//App target:
  
  public protocol BookViewDataSource {
      var numberOfPages : Int { get }
  }
  
  extension Book : BookViewDataSource {
      public var numberOfPages : Int { return self.numberOfPages } 
  }
  </code></pre>
  
  <p>But what's the alternative? Rejected/failed ideas:</p>
  
  <ol>
  <li>View takes model directly. A common approach, always bad because it tightly couples the view and the model. Using a protocol-based interface allows easy swapping with mock objects at design time and at runtime. </li>
  <li>Different Names. Giving the protocol properties and struct properties different names would work, but clutters up the naming and is silly, because the whole point is the model object has almost exactly the data the view needs. We are keeping it in a framework (following WWDC 14 "Building Modern Frameworks" recommendation) to allow better reuse in a share extension. </li>
  <li>Model knows about Protocol. Now we are taking protocols written for views to define the data they need, and moving them into the framework. Ridiculous, but does altogether eliminate need for extension. </li>
  <li>Protocol extensions. If we can define a default implementation of the protocol that references self, then objects that fulfill the protocol will just access their getters? But while there's no inline error, the compiler (linker specifically) won't allow it, citing "protocol witness", insisting the Book still doesn't fulfill the protocol (we keep the extension to compute the properties it doesn't have).</li>
  </ol>
  
  <p>This whole thing seems like a common scenario, just to state that a type fulfills the protocol already. Are we missing any easy way to do this, or is there a reason why/how we should choose an above approach? Thx. </p>