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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:34:06+00:00 2026-05-20T10:34:06+00:00

I have an NSArray that looks like this: ArrayItem *thisone = [[ArrayItem alloc] initWithName:@The

  • 0

I have an NSArray that looks like this:

ArrayItem *thisone = [[ArrayItem alloc] initWithName:@"The Name" data1:@"Some data" data2:@"Some more data" image:@"theimage.jpg" range:0];

ArrayItem *thisone1 = [[ArrayItem alloc] initWithName:@"The Name" data1:@"Some data" data2:@"Some more data" image:@"theimage.jpg" range:0];

ArrayItem *thisoneagain = [[ArrayItem alloc] initWithName:@"The Name 2" data1:@"Some data2" data2:@"Some more data2" image:@"theimage2.jpg" range:1];

ArrayItem *thisoneagain1 = [[ArrayItem alloc] initWithName:@"The Name 2" data1:@"Some data2" data2:@"Some more data2" image:@"theimage2.jpg" range:1];

ArrayItem *thisoneagain2 = [[ArrayItem alloc] initWithName:@"The Name 2" data1:@"Some data2" data2:@"Some more data2" image:@"theimage2.jpg" range:1];

ArrayItem *thisoneyetagain = [[ArrayItem alloc] initWithName:@"The Name 3" data1:@"Some data3" data2:@"Some more data3" image:@"theimage3.jpg" range:2];

ArrayItem *thisoneyetagain1 = [[ArrayItem alloc] initWithName:@"The Name 3" data1:@"Some data3" data2:@"Some more data3" image:@"theimage3.jpg" range:2];

ArrayItem *thisoneyetagain2 = [[ArrayItem alloc] initWithName:@"The Name 3" data1:@"Some data3" data2:@"Some more data3" image:@"theimage3.jpg" range:2];

ArrayItem *thisoneyetagain3 = [[ArrayItem alloc] initWithName:@"The Name 3" data1:@"Some data3" data2:@"Some more data3" image:@"theimage3.jpg" range:2];

self.ArrayItems = [[NSMutableArray alloc] initWithObjects:thisone,thisone1,thisoneagain,thisoneagain1,thisoneagain2,thisoneyetagain,thisoneyetagain1,thisoneyetagain2,thisoneyetagain3,nil];

and I would like to count the number of items in each “range” (as in there are 2 items with a range of 0, 3 with a range of 1, and 4 with a range of 2) and store the number of items for each range in separate variables. Any idea how to do this? ArrayItems.count just tells me how many there are in total.

  • 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-20T10:34:06+00:00Added an answer on May 20, 2026 at 10:34 am

    This is more of a general programming question rather than iOS specific, but I will give you the answer using Objective-C.

    After you create your array you can do the following:

    int range0=0;
    int range1=0;
    int range2=0;    
    for (ArrayItem* item in self.ArrayItems) {
    //Assuming range is an int property of ArrayItem we can switch on it.
        switch (item.range) {
            case 0:
                range0++;
                break;
            case 1:
                range2++;
                break;
            case 2:
                range3++
                break;
            default:
                break;
        }
    }
    

    This will give you the numer of items on each range stored on the range0, range1 and range2 variables.

    Using Tim’s Approach you can do something like this:

    NSUInteger counts[3] = {0,0,0};
    for(ArrayItem * item in self.ArrayItems) {
        counts[item.range]++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that looks like this: actualColor = 0; targetColors = [NSArray
I have a code snippet that looks like this: [tableView beginUpdates]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
Lets say I have a core data model like this one: Item attributes: name
I have an NSArray and I'd like to create a new NSArray with objects
I have an array named 'names' with strings looking like this: [name_23_something, name_25_something, name_2_something];
In my objective c class, I'd like to sort an array like this: NSArray
I have an NSArray of objects that all subclass with their different types from
I have NSDate object and I need to find from a NSArray (that has
I have a script that appends some rows to a table. One of the
Have you managed to get Aptana Studio debugging to work? I tried following this,

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.