0

I have a NSMutableArray like this.

2015-09-22 10:12:22.739 amigo[17198:6080591] Headers ************************ (
    {
    BidAcceptanceRide = 0;
    BidRejectionRide = 1;
    BidRide = 1;
    BookingCancellationByBuyer = 0;
    BookingCancellationBySeller = 0;
    BookingConfirmation = 3;
    BookingRemainder = 0;
    Review = 0;
    TotalNotification = 5;
}

)

What I want to do is check these each key value pairs and if the value is greater than 0 I want to add its key to another array. How can I do this? Please help me.

Thanks

1 Answer 1

1

You can try with following code and you can modify it as per your need.

  NSArray * arrHeaders; // Your existing array in which you have value.
    NSMutableArray * arrSortedData = [NSMutableArray array]; // New array in which you will add data.


    for (int i = 0; i < [arrHeaders count]; i++){

        NSDictionary * dicTeamp = [arrHeaders objectAtIndex:i];

        NSMutableDictionary * dicSortedData = [NSMutableDictionary dictionary]; // Dictionary where all keys and value which is greater than 0.

        for (int j = 0; j < [[dicTeamp allKeys] count]; j++){

            if([[dicTeamp valueForKey:[[dicTeamp allKeys] objectAtIndex:j]] intValue] > 0){
                [dicSortedData setValue:[dicTeamp valueForKey:[[dicTeamp allKeys] objectAtIndex:j]] forKey:[[dicTeamp allKeys]objectAtIndex:j]];
            }
        }
        [arrSortedData addObject:dicSortedData];
    }

    NSLog(@"Your sorted data = %@",arrSortedData);  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.