Match Game - Lesson 4, undeclared type Card


I don’t know why the error "Use of undeclared type ‘Card’ " is coming. Can someone help me, please?
Xcode Version 11.4


import Foundation

class Card {
var imageName = “”
var isFlipped = false
var isMatched = false


import Foundation

class CardModel {

func getCards() -> [Card] {
    // Declare an Array to store the generated cards
    var generatedCardsArray = [Card]()
    // Randomly generate pairs of cards
    for _ in 1...8 {
        // get a random number
        let randomNumber = arc4random_uniform(13) + 1
        // create the first card object
        let cardOne = Card()
        cardOne.imageName = "card\(randomNumber)"
        // create the second card object
        let cardTwo = Card()
        cardTwo.imageName = "card\(randomNumber)"
    // Randomize the array
    // Return the Array


The error is gone after restart Xcode, so why it’s need a restart?

Xcode is sometimes a bit buggy. When you do a lot of changes the build folder gets a bit messy. You can try Cleaning the build folder.

Shift + Option + Command + K supposedly does a deeper clean rather than just Shift + Command + K.

If that does not work then delete the build folder which is located in the path:

First close the project then use the Finder menu and select Go > Go to Folder and in that field presented copy the above path and paste that in.

The folder you want will have a name that starts with the project name so you would look for MatchApp (depending on your choice of project name when you created it).

When you locate it, select it and press Command + Delete and it will be moved to the trash.
Empty the trash and then reopen the project in Xcode. The build folder will be recreated and reindexed. Build it and see of the errors go away.

Restart Xcode if that does not work or Xcode starts behaving weirdly.

1 Like