如何在此代码上实现快速枚举

时间:2013-02-19 15:39:57

标签: iphone ios xcode

我想对此代码实施快速enumeration,请帮助我。

int xx;
int b=0;

for (xx=0 ; xx<(distancearray.count); xx++) {
    if ([NSNull null]!=[distancearray objectAtIndex:xx]&& 0 !=[[[distancearray objectAtIndex:xx] description] intValue] ) {
        b++;
        latitudeLabel.text=[NSString stringWithFormat:@" %d",b*100];
    }

}

2 个答案:

答案 0 :(得分:3)

试试这个:

for( id object in distancearray){
    if ([NSNull null]!=object && 0 !=[[object description] intValue] ) {
        b++;
        latitudeLabel.text=[NSString stringWithFormat:@" %d",b*100];
    }
}

答案 1 :(得分:0)

为简单起见:

for( id object in distancearray){
    if (object && [[object description] intValue] != 0) {
        b++;
        latitudeLabel.text=[NSString stringWithFormat:@" %d",b*100];
    }
}

了解迭代数组:How do I iterate over an NSArray?