2013-07-18 80 views
0

我一直在嘗試爲一副紙牌寫一個應用程序,但我一直在我的代碼中收到錯誤。錯誤在otherCard上,並且說快速枚舉循環中未聲明的標識符錯誤

未聲明的標識otherCard。

#define MATCH_BONUS 4 
#define MISMATCH_PENALTY 2 
#define FLIP_COST 1 

- (void)flipCardAtIndex:(NSUInteger)index 
{ 
    card *card = [self cardAtIndex:index]; 

    if (!card.isUnplayable){ 
     if(!card.isFaceUp){ 
      for (card *otherCard in self.cards) { 
       if (otherCard.isFaceUp && !otherCard.isUnplayable) { 
        int matchscore = [card match: @[otherCard]]; 
        if (matchscore) { 
         otherCard.unplayable = YES; 
         card.unplayable = YES; 
         self.score += matchscore * MATCH_BONUS; 
        } else { 
         otherCard.faceUp = NO; 
         self.score -= MISMATCH_PENALTY; 
        } 
        break; 
       } 
      } 
      self.score -= FLIP_COST; 
     } 
     card.faceUp = !card.isFaceUp; 
    } 
} 
+0

它告訴你錯誤是在哪一行嗎? –

+2

將你的'卡'類改爲'卡'。你在本地掩蓋它,所以每個循環都會失敗。 – thegrinner

回答

1

card類是由card變量掩蓋。

card *card = [self cardAtIndex:index]; 

這意味着每個迴路發生故障的位置:

for (card *otherCard in self.cards) { 

嘗試用大寫C更改cardCard(大寫類名是良好的作風太)。或者,您可以將card變量重命名爲flipCard之類的其他內容。