你好我正在一個項目上工作,我試圖添加一個NSUInteger到一個NSMutableArray。一般來說,我是Objective-C和C的新手。當我運行應用程序NSLog顯示爲空。添加NSUInteger到NSMutableArray
我很感激任何人都可以提供的幫助。
這裏是我的代碼
-(NSMutableArray *)flipCardAtIndex:(NSUInteger)index
{
Card *card = [self cardAtIndex:index];
[self.flipCardIndexes addObject: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;
}
NSLog(@"%@",self.flipCardIndexes[self.flipCardIndexes.count-1]);
return self.flipCardIndexes;
}
NSUInteger是「標」,而不是一個「對象」。您只能將「對象」添加到NSArray。但是,您可以將NSNumber添加到NSArray,而NSNumber是數字類型的通用「包裝器」類。請參閱NSNumber的規格。 –