for loop in objective c
Can someone help take a look at this method and advise please.. SOmethings seems not quite right.
for(int i = 0; i<sizeof(_annotation2) - 5 ; i++){
[a.annotationsPatients add开发者_如何学运维Object:[_annotation2 objectAtIndex:i]];
}
You cannot use sizeof()
to get the number of elements in an NSArray
. You use count
.
for(int i = 0; i<[_annotation2 count] - 5 ; i++){
[a.annotationsPatients addObject:[_annotation2 objectAtIndex:i]];
}
You're using sizeof
incorrectly. sizeof
gets the size of a given data type, not the length of what I assume is an NSArray
. To get the length of an NSArray
, use the count
method, like so:
NSUInteger arrayLength = [someArray count];
for (int x = 0; x < arrayLength; ++x)
{
// do whatever in here
}
Actually "count" method is used instead of "sizeof".
Review your code as below:
for(int i = 0; i<[_annotation2 count] - 5 ; i++){
[a.annotationsPatients addObject:[_annotation2 objectAtIndex:i]];
}
精彩评论