title: The difference between an any type and a generic type in swift
body: <p>What is the difference between an any type and generic type in swift?</p>
  
  <p>Any Type Example:</p>
  
  <pre><code>let swiftInt: Int = 1
  let swiftString: String = "miao"
  
  var array: [Any] = []
  array.append(swiftInt)
  array.append(swiftString)
  </code></pre>
  
  <p>Generic Type Example:</p>
  
  <pre><code>func duplicate&lt;T&gt;(item: T, numberOfTimes n: Int) -&gt; [T] {
    var buffer : [T] = []
    for _ in 0 ..&lt; n {
      buffer.append(item)
    }
    return buffer
  }
  </code></pre>
  
  <p>Is this a matter of preference because both appear to solve the same problem by being able to substitute the desired type.</p>