NSInteger计算时间4?

LaK*_*LaK 5 increment nsinteger ios

我不明白为什么这个NSInteger计数器增加到数据库行的真实值的4倍.也许这是愚蠢的,但我真的不明白......

谢谢到目前为止:)

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);
Run Code Online (Sandbox Code Playgroud)

Sur*_*oot 11

因为我是一个指针,你正在递增指针值,这很可能是以4为步长(NSInteger指针的大小).只需删除指针*引用就可以了.

NSInteger i = 0;

for ( NSDictionary *teil in gText ) {
Run Code Online (Sandbox Code Playgroud)

从理论上讲,你可能会这么做.

NSInteger *i;
*i = 0;
for ( NSDictionary *teil in gText ) {
...
*i = *i + 1;
...
Run Code Online (Sandbox Code Playgroud)

来自: 基础数据类型参考

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif
Run Code Online (Sandbox Code Playgroud)