NSInteger计算时间4? [英] NSInteger counts times 4?

查看:95
本文介绍了NSInteger计算时间4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I don't understand why this NSInteger counter increments to exactly 4 times the true value of database rows. Maybe this is stupid but I really just don't get it...

到目前为止感谢:)

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);


推荐答案

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

Because i is a pointer and you are incrementing the pointer value which will most likely be in steps of 4 (size of NSInteger pointer). Just remove the pointer * reference and you should be good.

NSInteger i = 0;

for ( NSDictionary *teil in gText ) {

理论上你可以这样做很难。

In theory you COULD do this the hard way.

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

来自:
基础数据类型参考

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

这篇关于NSInteger计算时间4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆