Does NSInteger Count 4 Times?

I do not understand why this NSInteger counter increases exactly 4 times the true value of database rows. Maybe this is stupid, but I just don’t understand ...

Thanks, bye:)

NSInteger *i;
i = 0;

for ( NSDictionary *teil in gText ) {

    //NSLog(@"%@", [teil valueForKey:@"Inhalt"]);

    [databaseWrapper addEntry:[teil valueForKey:@"Inhalt"] withTyp:[teil valueForKey:@"Typ"] withParagraph:[teil valueForKey:@"Paragraph"]];

    i+=1;
}

NSLog(@"Number of rows created: %d", i);
+5
source share
2 answers

Because I am a pointer, and you increase the value of the pointer, which will most likely be in step 4 (the size of the NSInteger pointer). Just remove the link to the * pointer, and you should be fine.

NSInteger i = 0;

for ( NSDictionary *teil in gText ) {

In theory, you CAN do this the hard way.

NSInteger *i;
*i = 0;
for ( NSDictionary *teil in gText ) {
...
*i = *i + 1;
...

C: Reference for types of reference data

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif
+11
source

inot declared as NSInteger, it is declared as a pointer to NSInteger.

a NSInteger - 4 , 1, 1 NSInteger 4 .

i = 0;
...
i += 1; //Actually adds 4, since sizeof(NSInteger) == 4
...
NSLog(@"%d", i); //Prints 4

- , NSInteger , . :

NSInteger i = 0;
+1

All Articles