0

I am using Xcode 5 , I write this method but unfortunately this error appear: USE OF UNDECLARED IDENTIFIER otherCard. Although I declare it in the for loop:

- (void)chooseCardAtIndex:(NSUInteger)index{
    card *card =[self cardAtIndex:index];
    if(card.isMatched){
        if(card.isChosen){
            card.chosen =NO;

        }else {
            for(card *otherCard in self.cards){
                if(otherCard.isChosen && !otherCard.isMatched){
                    int matchScore =[card match:@[otherCard]];
                    if(matchScore){
                        self.score +=matchScore;
                    } else {
                        self.score -= MISMATCH_PENALTY;
                    }

                }
            }

        }
    }

}

thank you in advance

6
  • 1
    Can you post some more details? At what line compiler is throwing an error. Commented Mar 29, 2014 at 3:08
  • tow lines 1. int matchScore =[card match:@[otherCard]] 2.if(otherCard.isChosen && !otherCard.isMatched) Commented Mar 29, 2014 at 3:10
  • Yes i Have declard it in the card class Commented Mar 29, 2014 at 3:14
  • do you know what is the problem ? Commented Mar 29, 2014 at 3:15
  • Using a lower cased class name is poor. Using the same name as an instance name is poorer. Commented Mar 29, 2014 at 3:16

2 Answers 2

2

This line may be throwing off the compiler:

card *card =[self cardAtIndex:index];

Is card the class type or the variable name? It can't be both.

Sign up to request clarification or add additional context in comments.

2 Comments

yes that right, now it is working, thank you , so it is not allowed to declare instance with same class name
Correct. As others have added below, you want to stick to the convention of naming all classes with two or three capital letters. That makes it clear to you (and others who may read your code later), which is a class and which is a variable. Good luck!
1

The problem is that when you defined variable card to be of class card earlier you hid the definition of class card. (A good reason to use the standard naming convention where class names always start with an Upper Case character.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.