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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:12:16+00:00 2026-06-14T01:12:16+00:00

Scenario: I have an expense tracking iOS Application and I am storing expenses from

  • 0

Scenario:

I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I do have a date attribute in my entity “Money” which is a parent entity for either an expense or an income.

Question:

What I want is to basically categorize my expenses for a given week, a month, or year and display it as the section header title for example : (Oct 1- Oct 7, 2012) and it shows expenses amount and related stuff according to that particular week. Two buttons are provided in that view, if I would press the right button, it will increment the week by a week (Oct 1- Oct 7, 2012 now shows Oct8 – Oct 15, 2012) and similarly the left button would decrement the week by a week.

My question is how would I achieve the above mentioned. I have some pseudo code written – Any help would be appreciated.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(date == %@)", dateToFilterFor];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Expense" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"SomeCacheName"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

What should be the predicate in order to filter it by a week? Also, I am thinking to have a section name in fetched result controller, but what would it be?

  • 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-14T01:12:17+00:00Added an answer on June 14, 2026 at 1:12 am

    Assuming that user has selected Oct 1 and Oct 7,

    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"MM/dd/yyyy"];
    
    NSString *str1 = @"10/01/2012";
    NSDate *date1 = [formatter dateFromString:str1];
    
    NSString *str2 = @"10/07/2012";
    NSDate *date2 = [formatter dateFromString:str2];
    

    Use it as,

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@)", date1, date2];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Expense" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];
    [fetchRequest setPredicate:predicate];
    
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"SomeCacheName"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;
    

    In order to add the dates,

    int addDaysCount = 7; //try with negative values for fetching previous week.
    
    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
    [dateComponents setDay:addDaysCount];
    
    NSDate *newDate1 = [[NSCalendar currentCalendar] 
                                  dateByAddingComponents:dateComponents 
                                                  toDate:date1 options:0];
    NSDate *newDate2 = [[NSCalendar currentCalendar] 
                                  dateByAddingComponents:dateComponents 
                                                  toDate:date2 options:0];
    

    Use the above predicate with newDate1 and newDate2 to fetch new expense corresponding to these dates.

    If you want to get the sunday of a particular week, use NSDateComponents.

    NSDateComponents *components = [NSDateComponents new]; 
    components.weekday = 1;//represents sunday 
    components.year = 2012; 
    components.weekOfMonth = 1;
    components.month = 10; //etc..
    
    NSDate *date1 = [[NSCalendar currentCalendar] dateFromComponents: components]; 
    

    For more details on NSDateComponents and its properties check

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

Sidebar

Related Questions

Scenario : I have an expense tracking iOS Application and I am storing expenses
I have an expense tracking iOS Application using Core Data Model: Scenario: -> An
Scenario: I have an application that pulls data from a SQL database as well
Scenario: I have an application that has a config table which stores the config
Scenario : I have a users table in my application. I also have two
Scenario: I have Window Application to be installed/updated from website. User needs to enter
Scenario: I have a console application that needs to access a network share with
Scenario I have recently graduated from university with a degree in Computer Science. My
Scenario :- I have to call MYSQL stored procedure from PHP and do some
Scenario: I have imported the data from SQl Server to HDFS. The data stored

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.