Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build An iTunes Search App Modeling iTunes Search Results Exploring the iTunes Search API

Making my own app

Hi community, I know this is not completely related but. I am trying to make my own app, is about a concentration game. Given a bunch of cards facing down, you have to find the pairs. But for some reason my app doesn't show the rest of the emojis (I decided to put emojis instead of images) I think the mistake is in the view controller, inside the touchCardHelper function. If you see it you will understand. However I have try many things so is changing the instance of the structure, not making more copies of the structure, cuze that's what it seems to be doing. I have not idea whatsoever of what is going on. Please help me :(

P.D. I have already wrote the rest of the code within the touchCardHelper function so the game does more things, however I just put this here because not even the basic actions are working :(

Modeling the card structure code:

public struct Card { var identifier = 0

var isFaceUp = false

var isMatched = false

var isRecognizable = 0

var emoji = "😈"

var hasEmoji = false


Modeling the game class structure:

public class Game { var cards = Card

var points = 3

let emojis = ["👽", "🥳", "😈", "👾"]

init(PairOfCards: Int) {
    for _ in 1...PairOfCards {
        var card = Card()
        card.identifier += 1
        for unicode in emojis {
            if card.hasEmoji == false {
                card.emoji = unicode
                card.hasEmoji = true


Modeling the view controller:

 var kakaoGame = Game(PairOfCards: 2)

@IBAction func touchCard(_ sender: UIButton) {

func cardChanger (cardInstance: inout Card) -> Void
    cardInstance.isFaceUp = true

func touchCardHelper(_ button: UIButton) -> Void {
    print("Hey I am working")
    for var eachCard in kakaoGame.cards {
        print("entering the for loop")
        if button.backgroundColor == #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) && eachCard.isFaceUp == false {
            print("entering the if statement")
            button.setTitle(eachCard.emoji, for: UIControl.State.normal)
            cardChanger(cardInstance: &eachCard)
            button.backgroundColor = #colorLiteral(red: 0.9999960065, green: 1, blue: 1, alpha: 1)


1 Answer

I think the problem is the fact that apparently given the pointer that represents each element within each iteration in a for loop CAN'T change the properties nor the element itself. Do somebody can confirm this please?