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 8470141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:26:03+00:00 2026-06-10T16:26:03+00:00

I have an array full of strings with each string being a name. Some

  • 0

I have an array full of strings with each string being a name. Some names may be the same while some may be different. The language I’m working in is objective-C. I want to be able to find out which name is most popular from this array (the array will be dynamic based on information given to the app from the user). I am not sure how to make this happen EFFICIENTLY. If someone could expand on this or provide an example, it would be appreciated.

Thank you

Example:

NSArray *nameArray= [[NSArray alloc] initWithObjects @"james", @"megan", @"lauren", @"mike" @james", nil]; 

  //james would be the most popular name
  • 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-10T16:26:05+00:00Added an answer on June 10, 2026 at 4:26 pm

    Use NSCountedSet and then find the object with highest count using countForObject: method.

    //create count set from array
    NSCountedSet *setOfObjects = [[NSCountedSet alloc] initWithArray:yourArrayhere];
    
    //Declaration of objects
    NSString *mostOccurringObject = @"";
    NSUInteger highestCount = 0;
    
    //Iterate in set to find highest count for a object
    for (NSString *strObject in setOfObjects)
    {
        NSUInteger tempCount = [setOfObjects countForObject:strObject];
        if (tempCount > highest)
        {
            highestCount = tempCount;
            mostOccurringObject = strObject;
        }
    }
    

    Checking the result:

    NSLog(@"Most frequent string: %@ with count: %i", mostOccurringObject,highestCount);
    

    Credit goes to @Evan Mulawski answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a string array full of different vodkas, what i want to
I have array of strings, String[] data and it's 10 elements has value P
I have an array unsortedPosts full of dictionaries, which look like this if I
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
When I have array of objects, when I type the name of variable in
I have a string full of html & which reads Dim strHml as string
I have a simple referrers table with three columns: Referrer //string name of partner
I have a JSON string array of objects like this. [{id:4,rank:adm,title:title 1}, {id:2,rank:mod,title:title 2},
I have a constants class full of a bunch of final static strings. I
I have a bunch of String s I'd like a fast lookup for. Each

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.