title: Is there no default(T) in Swift?
body: <p>I'm trying to port the Matrix example from Swift book to be generic.</p>
  
  <p>Here's what I got so far:</p>
  
  <pre><code>struct Matrix&lt;T&gt; {
      let rows: Int, columns: Int
      var grid: T[]
  
      init(rows: Int, columns: Int, repeatedValue: T) {
          self.rows = rows
          self.columns = columns
  
          grid = Array(count: rows * columns, repeatedValue: repeatedValue)
      }
  
      func indexIsValidForRow(row: Int, column: Int) -&gt; Bool {
          return row &gt;= 0 &amp;&amp; row &lt; rows &amp;&amp; column &gt;= 0 &amp;&amp; column &lt; columns
      }
  
      subscript(row: Int, column: Int) -&gt; T {
          get {
              assert(indexIsValidForRow(row, column: column), "Index out of range")
              return grid[(row * columns) + column]
          }
          set {
              assert(indexIsValidForRow(row, column: column), "Index out of range")
              grid[(row * columns) + column] = newValue
          }
      }
  }
  </code></pre>
  
  <p>Note that I had to pass <code>repeatedValue: T</code> to the constructor.</p>
  
  <p>In C#, I would have just used <code>default(T)</code> which would be <code>0</code> for numbers, <code>false</code> for booleans and <code>null</code> for reference types. I understand that Swift doesn't allow <code>nil</code> on non-optional types but I'm still curious if passing an explicit parameter is the only way, or if I there is <em>some</em> equivalent of <code>default(T)</code> there.</p>