[Solved] Objective-C, How to count the number of TRUE booleans? [duplicate]


To Understand as Simple manner:

int trueCount = 0;
int falseCount = 0;


for (<#initialization#>; <#condition#>; <#increment#>) {

  BOOL test3 = [test containsCoordinate:tg];

    if (test3) {

        trueCount++;
    }
    else{

        falseCount++;
    }

}

NSLog(@"True : %i",trueCount);
NSLog(@"False : %i",falseCount);

Implementation:

-(void)markers{
    NSURL *url = [NSURL URLWithString:@"http://example.com/api/s.php"];
    data = [NSData dataWithContentsOfURL:url];
    NSError *error;
    NSMutableArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
    if (error != nil)
    {
        NSLog(@"Could not fetch data !");
    }
    NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&sensor=false", coordi, f_query]];
    NSData *jsonData = [NSData dataWithContentsOfURL:jsonURL];
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    id array2 = [dataDictionary objectForKey:@"routes"];
    if([array2 count] > 0) {
        NSDictionary *routes = [dataDictionary objectForKey:@"routes"][0];
        NSDictionary *route = [routes objectForKey:@"overview_polyline"];
        NSDictionary *legs = [routes objectForKey:@"legs"][0];
        NSString *overview_route = [route objectForKey:@"points"];
        CLLocationCoordinate2D location;

        int trueCount = 0;
        int falseCount = 0;


        for (NSDictionary *dictionary in array)
        {
            location.latitude = [dictionary[@"latitude"] floatValue];
            location.longitude = [dictionary[@"longitude"] floatValue];
            CLLocationCoordinate2D tg = CLLocationCoordinate2DMake(location.latitude, location.longitude);
            GMSCoordinateBounds *test = [[GMSCoordinateBounds alloc]initWithPath:path];
            BOOL test3 = [test containsCoordinate:tg];

            if (test3) {

                trueCount++;
            }
            else{

                falseCount++;
            }



            {
                if (test3 == 1)
                {
                    polyline.strokeColor = [UIColor colorWithRed:0.259 green:0.698 blue:0.894 alpha:1.0];
                    marker.position = CLLocationCoordinate2DMake(location.latitude, location.longitude);
                }else if (test3 == 0)
                {
                    polyline.strokeColor = [UIColor colorWithRed:0.647 green:0.839 blue:0.016 alpha:0.7];
                    marker.position = CLLocationCoordinate2DMake(0, 0);
                }
            }
        }

        NSLog(@"True : %i",trueCount);
        NSLog(@"False : %i",falseCount);


    }

1

solved Objective-C, How to count the number of TRUE booleans? [duplicate]