title: Difference between Generics and AnyObject in Swift
body: <p>Consider this <code>myFilter</code> function that takes in a generic argument and filters the array based on the predicate. This is same as the <code>filter()</code> function provided by Swift. </p>
  
  <pre><code>func myFilter&lt;T&gt;(source: [T], predicate:(T) -&gt; Bool) -&gt; [T] {
    var result = [T]()
    for i in source {
      if predicate(i) {
        result.append(i)
      }
    }
    return result
  }
  </code></pre>
  
  <p>How is this different from, </p>
  
  <pre><code>func myFilter(source: [AnyObject], predicate:(AnyObject) -&gt; Bool) -&gt; [AnyObject] {
    var result = [AnyObject]()
    for i in source {
      if predicate(i) {
        result.append(i)
      }
    }
    return result
  }
  </code></pre>
  
  <p>Aren't we achieving the point of generics even in the latter example? </p>