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

  • Home
  • SEARCH
  • 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 7597943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:17:00+00:00 2026-05-30T22:17:00+00:00

I would like to ask how could I count object type inside array. For

  • 0

I would like to ask how could I count object type inside array. For example

this is my dataclass

+ (id)LocationWithID:(NSString *)UniqueID name:(NSString *)name address:(NSString *)address latitude:(float )latitude longitude:(float )longitude locationtype:(NSString *)locationtype country:(NSString *)country distance:(float )distance;

and this is my array

[array addObject:[dataclass LocationWithID:UniqueID name:name address:address latitude:latitude longitude:longitude locationtype:locationtype country:country distance:distance]];

and i would like to count how many country in this object. Normally we use
[array count];
but this will count all the object in the array. Now in my case i want to count non-repeated object for example i got an array contain 3 United kingdom, 5 USA, 7 Japan, 3 China and the result i want is country type = 4.

I would like to create several section for Table View according to the country type. Anyone?

  • 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-05-30T22:17:02+00:00Added an answer on May 30, 2026 at 10:17 pm

    You can use a dictionary to put objects with the same country in a separate array:

    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    for (dataclass *location in array) {
        if (![dictionary objectForKey:location.country]) {
            [dictionary setObject:[NSMutableArray array] forKey:location.country];
        }
        [(NSMutableArray *)[dictionary objectForKey:location.country] addObject:location];
    }
    

    Now, not only you can get the number of different countries like this:

    int countriesCount = [dictionary count];
    

    But also, it is easy to populate each section of your table view with locations from the corresponding country.

    You can retrieve all the locations for a specific country that has the name countryName, like this:

    NSArray *locationsForCountry = [dictionary objectForKey:countryName];
    

    You can also have the list of all the countries like this:

    NSArray *countries = [[dictionary keyEnumerator] allObjects];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask if anybody could provide an example of web.config for
I would like to ask in what situations could this even be possible? I've
I would like to ask how could I convert a string which inserted by
What I would like ask is best illustrated by an example, so bear with
I would like to ask for a reccomended solution for this: We have a
I would like to ask is there any way to achieve this functionality: I
Having read this past question for git, I would like to ask if there
I would like to ask on how you do ordering on an object with
I would like ask if there's a way to download an android layout from
I would like to ask for some simple examples showing the uses of <div>

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.