Swift: array check for object at index
<p>I have an data model object with several properties. I have a dynamic array that will sometimes have some but not all of the object properties inside of it.</p>

<p>How do I safely check if the array as anything at it's index</p>

<p>DataModel</p>

<pre><code>class Order{
     var item0:String?
     var item1:String?
     var item2:String?
}
</code></pre>

<p>Array:</p>

<pre><code>var myArray = [String]()
</code></pre>

<p>The guard statements are where I'm having issues checking to see if there are elements inside the array at different indexes.</p>

<p>Btw the array will never have more then 3 elements inside of it.</p>

<pre><code>let order = Order()
order.item0 = "hat"
order.item1 = "sneakers"

myArray.append(order.item0)
myArray.append(order.item1)
//sometimes there may or may not be item2

let placedOrder = Order

//These guard statements aren't working
guard case let placedOrder.item0 = myArray[0] else {return}

guard case let placedOrder.item1 = myArray[1] else {return}

//There isn't anything at myArray[2] but I need to safely check anyway
guard case let placedOrder.item2 = myArray[2] else {return}
</code></pre>