Q:

Is it possible to shorten a lot of code which constantly checks for booleans

I have different UIButtons all over my view. All UIButtons have a tag and have an image to represent a card. Some UIButtons are placed behind other cards, and can be "unlocked" if certain card has succesfully been played. The way I am checking if the behind cards can be unlocked is as followed:
if card1.enabled == false && card2.enabled == false {

unlockCard3()

}
if card3.enabled == false && card4.enabled == false {

unlockCard5()

}
if card8.enabled == false && card5.enabled == false {

    unlockCard11()

    }

If any card is been succesfully played, I disenabled them to get above function to work. It does work, but it is alot/repeating of code. I am curious if there is a way to shorten this code. See this image:  (left one). In this picture, the card to the right and top from the spades of 10 should be unlocked when the spades of 10 is succesfully played. The left card from the spades of 10 only should be unlocked when the spades of 6 is succesfully unlocked. All those checks and long codes... There has to be a way to make this process easier. Thank you for every suggestion.

A:

Put your buttons in an array and use a second array to represent the relationships of the cards:
let buttons = [button0, button1, button2, button3, button4, button5, button6, button7, button8, button9, button10, button11]

let relatives = [(1, 2, 3), (3, 4, 5), (5, 8, 11)]

for (card1, card2, card3) in relatives {
    if !buttons[card1].enabled && !buttons[card2].enabled {
        unlockCard(card3)
    }
}

