Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Instance member cannot be used on type 'ViewController' [duplicate]

Tags:

xcode

ios

swift

I am making a Concentration game by following along with lectures online from the stanford course, and I am getting an error for one part of my code. I am getting the error "Instance member 'cardButtons' cannot be used on type 'ViewController'", but the code seems to be working for the instructor. Could someone help me fix this? Here is part of the code. Error occurs in the 4th line

import UIKit

class ViewController: UIViewController {

@IBOutlet var cardButtons: [UIButton]!

lazy var game = Concentration(numberOfPairsOfCards: cardButtons.count / 2)

var flipCount = 0 {
    didSet {
        flipCountLabel.text = "Flips: \(flipCount)"
    }
}

@IBOutlet weak var flipCountLabel: UILabel!


@IBAction func touchCard(sender: UIButton) {
    flipCount += 1
    if let cardNumber = cardButtons.indexOf(sender) {
        game.chooseCard(at: cardNumber)
        updateViewFromModel()
    } else {
        print("chosen card was not in array cardButtons")
    }

}

func updateViewFromModel() {
    for index in cardButtons.indices {
        let button = cardButtons[index]
        let card = game.cards[index]
        if card.isFaceUp {
            button.setTitle(emoji, forState: UIControlState.Normal)
            button.backgroundColor = UIColor.whiteColor()
        } else {
            button.setTitle("", forState: UIControlState.Normal)
            button.backgroundColor = card.isMatched ? UIColor.clearColor() : UIColor.orangeColor()
        }

    }
}

    var emojiChoices = ["🍒", "🍧", "🍉", "🍟", "🍫", "🍡", "🍰", "🍓", "🍑", "🍿"]

func emoji(for card:Card) -> String {
    return "?"
}

}

like image 418
Samyu Ravikumar Avatar asked Oct 20 '25 09:10

Samyu Ravikumar


1 Answers

Change this line

 var game : Concentration {

    return  Concentration(numberOfPairsOfCards: self.cardButtons.count / 2)

}
like image 68
Sh_Khan Avatar answered Oct 22 '25 04:10

Sh_Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!