I am moving a card game written in Objective-C to Swift. I have 2 arrays in my Hand class, both of size 3, one holding the 3 side-by-side down cards and the other holding the up cards that are on top of the down cards. The up cards and the uncovered down cards could be played, and so the arrays might hold some cards and have some elements nil, because the array cells are handling the actual positions of the cards. These are declared as
var downCards: [Card] = []
var upCards: [Card] = []
downCards.reserveCapacity(3)
upCards.reserveCapacity(3)
In Objective C, the following code, to tell me if there was an uncovered down card, worked fine:
if ((handOfCurrentPlayer.upCards[cardLeft] == nil) &&
(handOfCurrentPlayer.downCards[cardLeft] != nil)) {}
But in Swift, I get "Comparing non-optional value of type 'Card' to 'nil' always returns false"
I'm quite new to Swift, and can't figure out how to either declare the arrays differently or use optionals and unpacking to be able to check for missing cards (in other words, nil).