2013-02-19 52 views
-1

我想對此代碼快速實現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]; 
    } 

} 

回答

3

嘗試這種情況:

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