Reputation: 83
I hava an array feed which contains a set of values when i log it out in the console. which looks like this in my log.
Final Feed : ( { hello = red; }, { hello = green; }, { hello = blue; }, { hello = blue; }, { hello = blue; }
However, when i use a for loop to loop the index to retrieve the values of "blue" and do a counting on how many "blue" it fails.
here is my codes
- (void)parserDidEndDocument:(NSXMLParser *)parser {
NSLog(@"Final Feed : %@",feeds);
int count = 0;
int i;
NSString *value;
for (i = 0; i < [feeds count]; i++) {
NSString *bookTitle = [feeds objectAtIndex:i];
if([[feeds objectAtIndex:i] isEqual: @"{hello = blue;}"]){
count++;
}
}
NSLog(@"Total Warning count is: %d",count);
}
The question now is how do i loop the array name feeds which contains the value "blue" and do a count?
Upvotes: 0
Views: 50
Reputation: 5148
because feeds
is array of dictionary so try following code:
NSInteger count = 0;
for (NSDictionary *feed in feeds) {
if ([feed[@"hello"] isEqualToString:@"blue"]) {
count++;
}
}
NSLog(@"%ld", (long)count);
Upvotes: 1