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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:31:10+00:00 2026-05-14T19:31:10+00:00

I am working on my first iPhone application and I’ve hit a wall. I’m

  • 0

I am working on my first iPhone application and I’ve hit a wall. I’m trying to develop a ‘statistics’ page for a three entity relationship. My entities are the following:

Department – Name, Address, Building, etc.
People – Name, Gender (BOOL), Phone, etc

If I have fetched a specific department how do I filter those results and only return people that are Male (Gender == 0)?

If I do

NSLog(@"%d", [department.people count]);

I get the correct number of people in that department so I know I’m in the neighborhood. I know I could re-fetch and modify the predicate each time but with 20+ stats in my app that seems inefficient. Thanks for any advice!

  • 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-14T19:31:11+00:00Added an answer on May 14, 2026 at 7:31 pm

    You don’t need to refetch:

    NSPredicate* pred = [NSPredicate predicateWithFormat:@"gender == NO"];
    NSUInteger count = [[department.people filteredArrayUsingPredicate:pred] count];
    NSLog(@"%lu", (unsigned long)count);
    

    Somehow gender==NO still looks strange though 😉

    If copying is too expensive, you could use enumerators instead. E.g.:

    NSUInteger CountIf(NSEnumerator* en, NSPredicate* pred) {
        NSUInteger count = 0;
        id obj;
        while (obj = [en nextObject]) {
            if([pred evaluateWithObject:obj]) 
                ++count;
        }
        return count;
    }
    
    NSUInteger count = CountIf([department.people objectEnumerator], predicate));
    

    … though this would be ideally moved to a suitable category as say countOfObjectsMatchingPredicate:.

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

Sidebar

Related Questions

I am new to iPhone programming and working on my first real application (i.e.
I am working on an offline-mode iPhone application in which the first time data
I'm new to iPhone and Apple development and working on my first application. It
I'm working on finishing up my server for my first iPhone application, and I
I'm working on the Android version of an application I first created on iPhone
I have my first sample iPhone application - some version of TicTacToe. It's working
I'm building(trying ... ) an iPhone application. My first user story is a login
I am working on my first application for iPhone and I'm facing this weird
I'm working on my first Core Data project (on iPhone) and am really liking
I'm working through the Stanford iPhone podcasts and have some basic questions. The first:

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.