你好我正在研究一个项目,我正在尝试将NSUInteger添加到NSMutableArray.我是Objective-C和C的新手.当我运行应用程序时,NSLog显示为null.
我很感激任何人都能提供的帮助.
这是我的代码
-(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;
}
Run Code Online (Sandbox Code Playgroud) 我正在研究一个项目,并且我被教导在构造函数中实例化变量.我在使用ArrayList思想时遇到了一些麻烦.您能否提出一些最佳实践,我是否需要使用实例变量定义ArrayList,或者我可以在构造函数中执行此操作.谢谢你的建议!我有一个我正在谈论的内容的例子:
//imports
import java.util.*;
import java.lang.*;
public class ArrayListConstructorDemo
{
//instance variables/attributes
String string;
List<String> list;// for example does this line need to say List<String> list = new ArrayList<String>();
//constructors
public ArrayListConstructorDemo()
{
String string = "null";
List<String> list = new ArrayList<String>();//is there anyway I can do this here instead of 6 lines up?
}//end default constructor
public ArrayListConstructorDemo(String string,List<String> list)
{
this.string = string;
this.list = list;
}//end generic constructor
//observers/getters/accessors
public String getString(){return string;}//end method getString()
public List<String> …Run Code Online (Sandbox Code Playgroud)