Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:00:10+00:00 2026-06-14T13:00:10+00:00

i have an array of dictionary objects with repeated objects, i need to make

  • 0

i have an array of dictionary objects with repeated objects, i need to make another array with no repeated objects with another key that represents the number of times that object was repeated.

Example:

object A (key1, key2)
object B (key1, key2)
object C (key1, key2)
object B (key1, key2)
object B (key1, key2)

Result,with new dictionary array:

object A (key1, key2, count(1))
object B (key1, key2, count(3))
object C (key1, key2, count(1))

Im having a hard time since im new to NSDictionary objects, the code so far:

for(int j = 1; j < [objects count]; j++)
{
    for(int k = j+1;k < [objects count]-j;k++)
    {
        NSMutableDictionary *item1 = [objects objectAtIndex:j];
        NSMutableDictionary *item2 = [objects objectAtIndex:k];

        NSString *str1 = [item1 valueForKey:@"setArrivalAirportOrCode"];
        NSString *str2 = [item2 valueForKey:@"setArrivalAirportOrCode"];

        NSLog(@"%@==%@ ???",str1,str2);
        if([str1 isEqualToString:str2])
            NSLog(@"%@==%@",str1,str2);
    }
}

Im trying to count the objects and copy them to a new array, i am not sure if i am going in the right direction, sorry for my poor English and please don’t down-vote, just ask me anything i am always online.

Thanks in Advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:00:12+00:00Added an answer on June 14, 2026 at 1:00 pm

    Create a NSCountedSet and it will take care of the counting for you.

    In this example, I used NSString objects but it can be done with any type of object:

    NSString        *stringA    = @"stringA";
    NSString        *stringB    = @"stringB";
    NSString        *stringC    = @"stringC";
    NSArray         *array      = [NSArray arrayWithObjects:stringA, stringB, stringC, stringB, stringB, nil];
    NSCountedSet    *countedSet = [NSCountedSet setWithArray:array];
    
    NSLog(@"%@", countedSet);
    // Results:  <NSCountedSet: 0x6b35790> (stringA [1], stringB [3], stringC [1])
    

    In order to get the count, you use:

    NSLog(@"%d", [countedSet countForObject:stringB]);
    // Result:  3
    

    In order to get the results in a separate array (note that you lose the counts, so use the counted set for that), use:

    NSArray *array2 = [countedSet allObjects];
    NSLog(@"%@", array2);
    /*
     * (
     * stringA,
     * stringB,
     * stringC
     * )
     */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does VBA have dictionary structure? Like key<>value array?
I have a NSDictonary object that I am setting a set of objects as
I am trying to build an array that contains arrays of dictionary objects in
I have an array of custom objects. The objects includes a dictionary. Something like
I have a class that I use to setup objects in an array. In
I have two NSMutableArrays(initialized from plist file contents) that contains Dictionary objects. Could anyone
I have an array, that represents an inventory, with nearly 50 elements (items: some
i have an array list of custom objects. each object contains a value i
Can I use an Array of Dictionary objects? I have an XML which I
If I have an NSArray (or mutable array) with several dictionary objects (each dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.