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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:00:02+00:00 2026-05-31T22:00:02+00:00

I have an entity with 2 attributes, an NSDate and a boolean value. (this

  • 0

I have an entity with 2 attributes, an NSDate and a boolean value. (this is going to be a large “table”)

I need to count all YES and NO values for the boolean between two dates, grouped by days. How can i do this?

The result I'm looking for is 
{
totalYes = 10,
totalNo = 5,
date = dd-mm-yyyy
},
{
totalYes = 15,
totalNo = 3,
date = dd-mm-yyyy
},

etc

Thanks

  • 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-31T22:00:04+00:00Added an answer on May 31, 2026 at 10:00 pm

    You can try this approach:

    1)Get all the enteties with YES,sorted by date

    2)Go trough this array and fill array with dictionaries with day value and number of yeses

    3)Then, do the ame thing with noe’s,adding number of no to that array of dictionaries.

    NSFetchRequest *request = [[NSFetchRequest alloc]init];
    request.entity = [NSEntityDescription entityForName:@"Day" inManagedObjectContext:context];
    request.predicate = [NSPredicate predicateWithFormat:@"yesorno = %@",YES];
    
    NSError *error = nil;
    request.sortDescriptors =[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]];
    //Here you get all the enteties with YES,sorted by date
    
    NSArray *days = [context executeFetchRequest:request error:&error];
    NSMutableArray *arrayOfDates = [NSMutableArray array];
    int firstDay = [[[NSCalendar currentCalendar]components:NSDayCalendarUnit fromDate:[[days objectAtIndex:0]date]]day];
    //Add the first day dictionary
    [arrayOfDates addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[[days objectAtIndex:0]date],@"Day", nil];
    
    int numberOfYes = 0;
    int dayNumber = 0;
    for(NSManagedObject *day in days)
    {   
        if( [[[NSCalendar currentCalendar]components:NSDayCalendarUnit fromDate:[day date]]day]>firstDay)
        {   
            //save number of yeses for the previous day,because we are done with it
            [[arrayOfDates objectAtIndex:dayNumber]setValue:[NSNumber numberWithInt:numberOfYes] forKey:@"NumberOfYes"];
            numberOfYes = 1;
            dayNumber++;
            firstDay = [[[NSCalendar currentCalendar]components:NSDayCalendarUnit fromDate:[day date]]day];//date with new day
            [arrayOfDates addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[day date],@"Day", nil];//Add this day dictionary to array
    
        }else
             {
                 numberOfYes++;
             }
    
    }
             //And somrthing similar to No 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity which looks like this: Entityname = Country with the attributes
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName
Say I have this entity with a lot of attributes. In the input form
I have an entity booking with the attributes name and value. Now i would
Let's say we have an entity that has attributes att1 and att2, where att1
I have an entity in core data that has 2 Attributes. One that is
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I have an abstract entity called Block which contains two attributes: column and order
I have an Core Data Entity with a number of attributes, which include amount(float),
I have a large sparse matrix representing attributes for millions of entities. For example,

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.