Swift - How to check if var is nil?
<p>I need to check if the last element in a dataArray is nil or not, so I am running this code:</p>

<pre><code> if(dataArray.last == nil){
     print("dataArray.last == nil");
 } else {
     print("dataArray.last != nil , last = " + String(dataArray.last));
 }
</code></pre>

<p>The weird thing is that it is printing this:</p>

<pre><code>dataArray.last != nil , last = Optional(nil)
</code></pre>

<p>It is saying that the last element is nil despite the if condition not being met. How is this possible?</p>

<p>Additionally, if I print <code>String(dataArray)</code> this is what is returned:</p>

<pre><code>[itemData,itemData , itemData , nil ,  nil , nil].
</code></pre>