title: How to use the reduce function on array of custom Object in Swift
body: <p>Considering a Swift Object <code>class Sheep</code> having a simple property <code>var position: CGRect</code></p>
  
  <pre><code>class Sheep {
      var position: CGRect
  
      init() {
          position = CGRectZero
      }
  }  
  </code></pre>
  
  <p>In an array of Sheep <code>Array&lt;Sheep&gt;</code> How can I get the <code>Sheep</code> with the highest <code>position.origin.y</code>?</p>
  
  <p>I tried the following but got an <code>error: could not find member y</code></p>
  
  <pre><code>func firstSheep(sheeps: Array&lt;Sheep&gt;) -&gt; Sheep
  {
       return sheeps.reduce(sheeps[0]) {max($0.position.origin.y, $1.position.origin.y)}
  }
  </code></pre>
  
  <p>All classes import</p>
  
  <pre><code>import Foundation
  import QuartzCore
  </code></pre>