我在求和两个 NSInteger 时遇到问题,我尝试使用简单的 int 但找不到答案。我的头文件中有这个:
@interface ViewController : UIViewController {
NSMutableArray *welcomePhotos;
NSInteger *photoCount; // <- this is the number with the problem
//static int photoCount = 1;
}
在我的实施领域,我有:
-(void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
photoCount = 0;
welcomePhotos = [NSMutableArray array];
int sum = photoCount + 1;
NSLog(@"0 + 1 = %i", sum);
}
las NSLog 总是打印0 + 1 = 4
另外,如果这样做:
if (photoCount < [welcomePhotos count]){
photoCount++;
NSLog(@"%i", photoCount);
}else{
photoCount = 0;
}
几次我得到:4, 8, 12。
所以它跳过了四个,但我无法理解为什么。