İki NSInteger toplama sorunu yaşıyorum, basit int ile çalıştım ama cevabı bulamıyorum. Benim başlık dosyası bu var:Toplam iki NSInteger yanlış sonuç veriyor
@interface ViewController : UIViewController {
NSMutableArray *welcomePhotos;
NSInteger *photoCount; // <- this is the number with the problem
//static int photoCount = 1;
}
benim uygulanması fiel ben vardır:
-(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 hep aynı 0 + 1 = 4
yazdırır yaparsanız eğer :
if (photoCount < [welcomePhotos count]){
photoCount++;
NSLog(@"%i", photoCount);
}else{
photoCount = 0;
}
Birkaç kez elde ederim: 4, 8, 12.
Yani dört tarafından atlıyor, ancak nedenini anlayamıyorum. NSInteger photoCount;
NSInteger için
ile değiştirin. Unutmayın ki "NSInteger" imzalı tamsayı için bir yazım hatasıdır (sisteme bağlı olarak 32-bit veya 64-bit). –
belki de NSInteger, çalışma zamanınızdaki farklı değerleri alan formunuzun (32 bit veya 64 bit) bit sayısına göre özel bir int olduğu için olabilir. –